Hi Dan,
You can create TargetEndStyles for connector by writing some custom code. If your connector is called MyConnector, you need to first mark MyConnector as HasDoubleDerived=true in the property grid for the connector and then regenerate the code by Transforming all templates.
This will create a BaseClass for your connector named MyConnectorBase in the generated Connector.cs as well as the connector class itself MyConnector. Next, create a custom class (say MyLinkDecorator) that will be the Customized Target End Style for your connector. This class will inherit from Modeling.Sdk.Diagrams.LinkDecorator class and must implement the GetPath method that returns the lines that should be drawn for the connector.
Next, write a partial class extending the MyConnector class and override the InitializeInstanceResources() method with implementation exactly as base but the only change will be that this.SetDecorators should be passed an instance of your newly created MyLinkDecorator instead of one of the default TargetEndStyle Decorators.
Recompile your project and you are all set to go!
Here is some sample code snippet to get you going:
using DslModeling = global::Microsoft.VisualStudio.Modeling;
using DslDesign = global::Microsoft.VisualStudio.Modeling.Design;
using DslDiagrams = global::Microsoft.VisualStudio.Modeling.Diagrams;
using System.Drawing.Drawing2D;
namespace Microsoft.Language6
{
/// <summary>
/// Double-derived base class for DomainClass ExampleConnector
/// </summary>
public partial class ExampleConnector : ExampleConnectorBase
{
/// <summary>
/// Initializes resources associated with this connector instance.
/// </summary>
protected override void InitializeInstanceResources()
{
base.InitializeInstanceResources();
this.SetDecorators(null, new MyLinkDecorator(), false);
}
}
public partial class MyLinkDecorator : DslDiagrams.LinkDecorator
{
protected override System.Drawing.Drawing2D.GraphicsPath GetPath(Microsoft.VisualStudio.Modeling.Diagrams.RectangleD bounds)
{
GraphicsPath path = DecoratorPath;
float centerX = (float)(bounds.Left + bounds.Width / 2);
float centerY = (float)(bounds.Top + bounds.Height / 2);
path.AddLine(centerX, ( float)bounds.Y, (float)bounds.Right, centerY);
path.AddLine(centerX, ( float)bounds.Y, (float)bounds.Left, centerY);
return path;
}
}
}
|