1 | ///
|
---|
2 | /// This file is part of ILNumerics Community Edition.
|
---|
3 | ///
|
---|
4 | /// ILNumerics Community Edition - high performance computing for applications.
|
---|
5 | /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
|
---|
6 | ///
|
---|
7 | /// ILNumerics Community Edition is free software: you can redistribute it and/or modify
|
---|
8 | /// it under the terms of the GNU General Public License version 3 as published by
|
---|
9 | /// the Free Software Foundation.
|
---|
10 | ///
|
---|
11 | /// ILNumerics Community Edition is distributed in the hope that it will be useful,
|
---|
12 | /// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | /// GNU General Public License for more details.
|
---|
15 | ///
|
---|
16 | /// You should have received a copy of the GNU General Public License
|
---|
17 | /// along with ILNumerics Community Edition. See the file License.txt in the root
|
---|
18 | /// of your distribution package. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | ///
|
---|
20 | /// In addition this software uses the following components and/or licenses:
|
---|
21 | ///
|
---|
22 | /// =================================================================================
|
---|
23 | /// The Open Toolkit Library License
|
---|
24 | ///
|
---|
25 | /// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
---|
26 | ///
|
---|
27 | /// Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
28 | /// of this software and associated documentation files (the "Software"), to deal
|
---|
29 | /// in the Software without restriction, including without limitation the rights to
|
---|
30 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
31 | /// the Software, and to permit persons to whom the Software is furnished to do
|
---|
32 | /// so, subject to the following conditions:
|
---|
33 | ///
|
---|
34 | /// The above copyright notice and this permission notice shall be included in all
|
---|
35 | /// copies or substantial portions of the Software.
|
---|
36 | ///
|
---|
37 | /// =================================================================================
|
---|
38 | ///
|
---|
39 |
|
---|
40 | using System;
|
---|
41 | using System.Drawing;
|
---|
42 | using ILNumerics.Drawing.Interfaces;
|
---|
43 | using ILNumerics.Exceptions;
|
---|
44 |
|
---|
45 | namespace ILNumerics.Drawing.Shapes {
|
---|
46 | /// <summary>
|
---|
47 | /// A simple single line
|
---|
48 | /// </summary>
|
---|
49 | public class ILLine : ILBorderedShape<C4bV3f> {
|
---|
50 |
|
---|
51 | #region attributes
|
---|
52 | ILLineProperties m_properties;
|
---|
53 | int m_autoLimitsUpdateCount = 0;
|
---|
54 | int m_updateCount = 0;
|
---|
55 |
|
---|
56 | public int AutoLimitsUpdateCount {
|
---|
57 | get { return m_autoLimitsUpdateCount; }
|
---|
58 | set { m_autoLimitsUpdateCount = value; }
|
---|
59 | }
|
---|
60 | int m_oldestVertexID;
|
---|
61 | #endregion
|
---|
62 |
|
---|
63 | #region properties
|
---|
64 | /// <summary>
|
---|
65 | /// [deprecated] line properties, use individual properties of ILLine instead
|
---|
66 | /// </summary>
|
---|
67 | public ILLineProperties Properties {
|
---|
68 | get { return m_properties; }
|
---|
69 | private set { m_properties = value; }
|
---|
70 | }
|
---|
71 | /// <summary>
|
---|
72 | /// the oldest vertex to be removed on the next Queue() call
|
---|
73 | /// </summary>
|
---|
74 | internal int OldestVertexID {
|
---|
75 | get { return m_oldestVertexID; }
|
---|
76 | }
|
---|
77 | /// <summary>
|
---|
78 | /// determines, if the line is to be drawn antialiased (on width > 1 only)
|
---|
79 | /// </summary>
|
---|
80 | public bool Antialiasing {
|
---|
81 | get { return m_properties.Antialiasing; }
|
---|
82 | set { m_properties.Antialiasing = value; }
|
---|
83 | }
|
---|
84 | /// <summary>
|
---|
85 | /// stipple pattern for the line, if Style is set to custom pattern
|
---|
86 | /// </summary>
|
---|
87 | public short Pattern {
|
---|
88 | get { return m_properties.Pattern; }
|
---|
89 | set { m_properties.Pattern = value; }
|
---|
90 | }
|
---|
91 | /// <summary>
|
---|
92 | /// scaling for the stipple pattern
|
---|
93 | /// </summary>
|
---|
94 | public float PatternScale {
|
---|
95 | get { return m_properties.PatternScale; }
|
---|
96 | set { m_properties.PatternScale = value; }
|
---|
97 | }
|
---|
98 | /// <summary>
|
---|
99 | /// line style, default: solid
|
---|
100 | /// </summary>
|
---|
101 | public LineStyle Style {
|
---|
102 | get { return m_properties.Style; }
|
---|
103 | set { m_properties.Style = value; }
|
---|
104 | }
|
---|
105 | /// <summary>
|
---|
106 | /// line width (pixels)
|
---|
107 | /// </summary>
|
---|
108 | public int Width {
|
---|
109 | get { return m_properties.Width; }
|
---|
110 | set { m_properties.Width = value; }
|
---|
111 | }
|
---|
112 | /// <summary>
|
---|
113 | /// inner color of the line
|
---|
114 | /// </summary>
|
---|
115 | public override Color FillColor {
|
---|
116 | get {
|
---|
117 | return m_properties.Color;
|
---|
118 | }
|
---|
119 | set {
|
---|
120 | m_properties.Color = value;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | #endregion
|
---|
124 |
|
---|
125 | #region constructors
|
---|
126 | /// <summary>
|
---|
127 | /// create new simple line with 2 ends
|
---|
128 | /// </summary>
|
---|
129 | /// <param name="panel"></param>
|
---|
130 | public ILLine (ILPanel panel)
|
---|
131 | : this (panel,2) { }
|
---|
132 | /// <summary>
|
---|
133 | /// create new line, determine number of vertices
|
---|
134 | /// </summary>
|
---|
135 | /// <param name="panel">panel hosting the scene</param>
|
---|
136 | /// <param name="numVertices">number of vertices for the line</param>
|
---|
137 | public ILLine (ILPanel panel, int numVertices)
|
---|
138 | : base (panel,numVertices) {
|
---|
139 | if (numVertices < 2)
|
---|
140 | throw new ILArgumentException("line must have at least 2 points!");
|
---|
141 | m_fillColor = Color.Black;
|
---|
142 | m_border.Visible = false;
|
---|
143 | m_oldestVertexID = 0;
|
---|
144 | m_properties = new ILLineProperties();
|
---|
145 | m_properties.Changed += new EventHandler(m_properties_Changed);
|
---|
146 | m_properties.Color = Color.Blue;
|
---|
147 | m_properties.Width = 2;
|
---|
148 | m_properties.Antialiasing = true;
|
---|
149 |
|
---|
150 | // default for border
|
---|
151 | m_border.Width = 5;
|
---|
152 | m_border.Antialiasing = true;
|
---|
153 | m_border.Color = Color.LightGray;
|
---|
154 |
|
---|
155 | m_autoLimitsUpdateCount = numVertices;
|
---|
156 | m_shading = ShadingStyles.Flat;
|
---|
157 | }
|
---|
158 | ///// <summary>
|
---|
159 | ///// create new line, give vertices positions also
|
---|
160 | ///// </summary>
|
---|
161 | ///// <param name="panel">panel hosting the scene</param>
|
---|
162 | ///// <param name="X">X coordinates</param>
|
---|
163 | ///// <param name="Y">Y coordinates</param>
|
---|
164 | ///// <param name="Z">Z coordinates</param>
|
---|
165 | //public ILLine(ILPanel panel, ILBaseArray X, ILBaseArray Y, ILBaseArray Z)
|
---|
166 | // : base (panel, X,Y,Z) {
|
---|
167 | // m_fillColor = Color.Black;
|
---|
168 | // m_border.Visible = false;
|
---|
169 | // m_oldestVertexID = 0;
|
---|
170 | // m_properties = new ILLineProperties();
|
---|
171 | // m_properties.Changed += new EventHandler(m_properties_Changed);
|
---|
172 | // m_properties.Color = Color.Blue;
|
---|
173 | // m_shading = ShadingStyles.Flat;
|
---|
174 | // m_autoLimitsUpdateCount = Vertices.Length;
|
---|
175 | //}
|
---|
176 | #endregion
|
---|
177 |
|
---|
178 | #region private helpers
|
---|
179 | void m_properties_Changed(object sender, EventArgs e) {
|
---|
180 | m_fillColor = m_properties.Color;
|
---|
181 | OnChanged();
|
---|
182 | }
|
---|
183 | protected override void IntDrawShape(ILRenderProperties props) {
|
---|
184 | if (m_vertCount == 0 || m_vertCount >= VerticesPerShape) {
|
---|
185 | m_renderer.Draw(props, this);
|
---|
186 | }
|
---|
187 | }
|
---|
188 | protected override void IntDrawLabel(ILRenderProperties props) {
|
---|
189 | if (m_vertCount == 0 || m_vertCount >= VerticesPerShape) {
|
---|
190 | if (!String.IsNullOrEmpty(m_label.Text) && m_vertCount > 1) {
|
---|
191 | ILPoint3Df cent = m_vertices[0].Position + m_vertices[1].Position;
|
---|
192 | m_label.Draw(props, cent / 2);
|
---|
193 | }
|
---|
194 | }
|
---|
195 | }
|
---|
196 | #endregion
|
---|
197 |
|
---|
198 | #region public interface
|
---|
199 | public void Queue(IILVertexDefinition vertex) {
|
---|
200 | SetVertex(m_oldestVertexID++, vertex);
|
---|
201 | if (m_oldestVertexID >= m_vertCount) {
|
---|
202 | m_oldestVertexID = 0;
|
---|
203 | }
|
---|
204 | if (m_updateCount++ < m_autoLimitsUpdateCount) {
|
---|
205 | bool signal = false;
|
---|
206 | m_positionMax = ILPoint3Df.Max(m_positionMax, vertex.Position, ref signal);
|
---|
207 | m_positionMin = ILPoint3Df.Min(m_positionMin, vertex.Position, ref signal);
|
---|
208 | if (signal) {
|
---|
209 | OnSizeChanged();
|
---|
210 | }
|
---|
211 | } else {
|
---|
212 | m_updateCount = 0;
|
---|
213 | Invalidate();
|
---|
214 | }
|
---|
215 | }
|
---|
216 | #endregion
|
---|
217 |
|
---|
218 |
|
---|
219 | }
|
---|
220 | }
|
---|