Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Utils/Styling/LinePenStyle.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 5.4 KB
Line 
1using System.Drawing;
2using System.Drawing.Drawing2D;
3
4namespace Netron.Diagramming.Core {
5  // ----------------------------------------------------------------------
6  /// <summary>
7  /// Extended <see cref="PenStyle"/> with extra properties for the design
8  /// of connections. 
9  /// <remarks>Although the .Net 2.0 framework allows you to set line caps
10  /// the result is, humbly said, rather poor. The caps are not drawn
11  /// proportionally and custom caps cannot be filled resulting in a 'not
12  /// implemented' exception.  So, the only working solution (read: hack)
13  /// I found is to draw the caps with a secondary pen whose size is bigger
14  /// than the base pen with which the line is drawn. Unfortunately this
15  /// hack cannot solely be implemented in this class, you need to fix it
16  /// in the painting routines.  Hopefully a solution will be around later
17  /// on.
18  /// </remarks>
19  /// </summary>
20  // ----------------------------------------------------------------------
21  public partial class LinePenStyle : PenStyle {
22
23    #region Fields
24
25    // ------------------------------------------------------------------
26    /// <summary>
27    /// Implementation of IVersion - the current version of
28    /// LinePenStyle.
29    /// </summary>
30    // ------------------------------------------------------------------
31    protected const double linePenStyleVersion = 1.0;
32
33    // ------------------------------------------------------------------
34    /// <summary>
35    /// the custom end cap
36    /// </summary>
37    // ------------------------------------------------------------------
38    private CustomLineCap mCustomEndCap;
39
40    // ------------------------------------------------------------------
41    /// <summary>
42    /// the custom start cap
43    /// </summary>
44    // ------------------------------------------------------------------
45    private CustomLineCap mCustomStartCap;
46
47    // ------------------------------------------------------------------
48    /// <summary>
49    /// the start cap
50    /// </summary>
51    // ------------------------------------------------------------------
52    private LineCap mStartCap = LineCap.NoAnchor;
53
54    // ------------------------------------------------------------------
55    /// <summary>
56    /// the end cap
57    /// </summary>
58    // ------------------------------------------------------------------
59    private LineCap mEndCap = LineCap.NoAnchor;
60
61    // ------------------------------------------------------------------
62    /// <summary>
63    /// the static generalization cap
64    /// </summary>
65    // ------------------------------------------------------------------
66    private static CustomLineCap mGeneralizationCap;
67
68    #endregion
69
70    #region Properties
71
72    // ------------------------------------------------------------------
73    /// <summary>
74    /// Gets the current version.
75    /// </summary>
76    // ------------------------------------------------------------------
77    public override double Version {
78      get {
79        return linePenStyleVersion;
80      }
81    }
82
83    /// <summary>
84    /// Gets the 'generallization cap'. This <see cref="CustomLineCap"/> is an arrow used in UML diagram to emphasize a generalization
85    /// of an object, i.e. an object is inherited and expanded or generalized.
86    /// </summary>
87    /// <value>The generallization cap.</value>
88    public static CustomLineCap GenerallizationCap {
89      get {
90        return mGeneralizationCap;
91      }
92    }
93
94    /// <summary>
95    /// Gets or sets the custom end cap.
96    /// </summary>
97    /// <value>The custom end cap.</value>
98    public CustomLineCap CustomEndCap {
99      get {
100        return mCustomEndCap;
101      }
102      set {
103        mCustomEndCap = value;
104      }
105    }
106
107    /// <summary>
108    /// Gets or sets the custom start cap.
109    /// </summary>
110    /// <value>The custom start cap.</value>
111    public CustomLineCap CustomStartCap {
112      get {
113        return mCustomStartCap;
114      }
115      set {
116        mCustomStartCap = value;
117      }
118    }
119
120    /// <summary>
121    /// Gets or sets the start cap.
122    /// </summary>
123    /// <value>The start cap.</value>
124    public LineCap StartCap {
125      get {
126        return mStartCap;
127      }
128      set {
129        mStartCap = value;
130      }
131    }
132
133    /// <summary>
134    /// Gets or sets the end cap.
135    /// </summary>
136    /// <value>The end cap.</value>
137    public LineCap EndCap {
138      get {
139        return mEndCap;
140      }
141      set {
142        mEndCap = value;
143      }
144    }
145    /// <summary>
146    /// The constructed pen
147    /// </summary>
148    /// <returns></returns>
149    public override Pen DrawingPen() {
150      Pen pen = base.DrawingPen();
151      /*
152       * Not a satisfying result, see the hack in the class comments above.
153      pen.CustomEndCap = mCustomEndCap;
154      pen.CustomStartCap = mCustomStartCap;
155      pen.StartCap = mStartCap;
156      pen.EndCap = mEndCap;
157       */
158      return pen;
159    }
160    #endregion
161
162    #region Constructor
163
164    /// <summary>
165    /// Initializes the <see cref="T:LinePenStyle"/> class.
166    /// </summary>
167    static LinePenStyle() {
168      Point[] ps = new Point[3] { new Point(-2, 0), new Point(0, 4), new Point(2, 0) };
169      GraphicsPath gpath = new GraphicsPath();
170      gpath.AddPolygon(ps);
171      gpath.CloseAllFigures();
172      mGeneralizationCap = new CustomLineCap(null, gpath);
173    }
174
175    public LinePenStyle() { }
176
177    #endregion
178  }
179}
Note: See TracBrowser for help on using the repository browser.