using System.Drawing; using System.Drawing.Drawing2D; namespace Netron.Diagramming.Core { // ---------------------------------------------------------------------- /// /// Extended with extra properties for the design /// of connections. /// Although the .Net 2.0 framework allows you to set line caps /// the result is, humbly said, rather poor. The caps are not drawn /// proportionally and custom caps cannot be filled resulting in a 'not /// implemented' exception. So, the only working solution (read: hack) /// I found is to draw the caps with a secondary pen whose size is bigger /// than the base pen with which the line is drawn. Unfortunately this /// hack cannot solely be implemented in this class, you need to fix it /// in the painting routines. Hopefully a solution will be around later /// on. /// /// // ---------------------------------------------------------------------- public partial class LinePenStyle : PenStyle { #region Fields // ------------------------------------------------------------------ /// /// Implementation of IVersion - the current version of /// LinePenStyle. /// // ------------------------------------------------------------------ protected const double linePenStyleVersion = 1.0; // ------------------------------------------------------------------ /// /// the custom end cap /// // ------------------------------------------------------------------ private CustomLineCap mCustomEndCap; // ------------------------------------------------------------------ /// /// the custom start cap /// // ------------------------------------------------------------------ private CustomLineCap mCustomStartCap; // ------------------------------------------------------------------ /// /// the start cap /// // ------------------------------------------------------------------ private LineCap mStartCap = LineCap.NoAnchor; // ------------------------------------------------------------------ /// /// the end cap /// // ------------------------------------------------------------------ private LineCap mEndCap = LineCap.NoAnchor; // ------------------------------------------------------------------ /// /// the static generalization cap /// // ------------------------------------------------------------------ private static CustomLineCap mGeneralizationCap; #endregion #region Properties // ------------------------------------------------------------------ /// /// Gets the current version. /// // ------------------------------------------------------------------ public override double Version { get { return linePenStyleVersion; } } /// /// Gets the 'generallization cap'. This is an arrow used in UML diagram to emphasize a generalization /// of an object, i.e. an object is inherited and expanded or generalized. /// /// The generallization cap. public static CustomLineCap GenerallizationCap { get { return mGeneralizationCap; } } /// /// Gets or sets the custom end cap. /// /// The custom end cap. public CustomLineCap CustomEndCap { get { return mCustomEndCap; } set { mCustomEndCap = value; } } /// /// Gets or sets the custom start cap. /// /// The custom start cap. public CustomLineCap CustomStartCap { get { return mCustomStartCap; } set { mCustomStartCap = value; } } /// /// Gets or sets the start cap. /// /// The start cap. public LineCap StartCap { get { return mStartCap; } set { mStartCap = value; } } /// /// Gets or sets the end cap. /// /// The end cap. public LineCap EndCap { get { return mEndCap; } set { mEndCap = value; } } /// /// The constructed pen /// /// public override Pen DrawingPen() { Pen pen = base.DrawingPen(); /* * Not a satisfying result, see the hack in the class comments above. pen.CustomEndCap = mCustomEndCap; pen.CustomStartCap = mCustomStartCap; pen.StartCap = mStartCap; pen.EndCap = mEndCap; */ return pen; } #endregion #region Constructor /// /// Initializes the class. /// static LinePenStyle() { Point[] ps = new Point[3] { new Point(-2, 0), new Point(0, 4), new Point(2, 0) }; GraphicsPath gpath = new GraphicsPath(); gpath.AddPolygon(ps); gpath.CloseAllFigures(); mGeneralizationCap = new CustomLineCap(null, gpath); } public LinePenStyle() { } #endregion } }