@@ -14,7 +14,14 @@ public partial class BedLeveler : Form
14
14
List < Vector3 > points = new List < Vector3 > ( ) ;
15
15
List < Vector2 > toMeasure = new List < Vector2 > ( ) ;
16
16
17
- public BedLeveler ( ) { InitializeComponent ( ) ; }
17
+ float ? LowerBound = null ;
18
+ float ? UpperBound = null ;
19
+
20
+ public BedLeveler ( )
21
+ {
22
+ InitializeComponent ( ) ;
23
+ Text += $ " { Application . ProductVersion } ";
24
+ }
18
25
19
26
private void MeasurePoint ( float x , float y )
20
27
{
@@ -133,13 +140,16 @@ private void BedPaint(object sender, PaintEventArgs e)
133
140
134
141
float min = ( from p in points select p . Z ) . Min ( ) ;
135
142
float max = ( from p in points select p . Z ) . Max ( ) ;
143
+ if ( LowerBound . HasValue ) min = LowerBound . Value ;
144
+ if ( UpperBound . HasValue ) max = UpperBound . Value ;
145
+
136
146
float range = max - min ;
137
147
138
148
using ( Font font = new Font ( "Arial" , 11.0f , FontStyle . Bold ) )
139
149
using ( StringFormat format = new StringFormat ( ) { Alignment = StringAlignment . Center , LineAlignment = StringAlignment . Center } )
140
150
foreach ( var p in points )
141
151
{
142
- float zPercent = range < 0.001 ? 1.0f : ( p . Z - min ) / range ;
152
+ float zPercent = Math . Max ( 0.0f , Math . Min ( 1.0f , range < 0.001 ? 1.0f : ( p . Z - min ) / range ) ) ;
143
153
float hue = Lerp ( 0 , 240 , zPercent ) ;
144
154
Color c = ColorFromHSV ( hue , 1.0 , 1.0 ) ;
145
155
@@ -228,5 +238,29 @@ private void SetZto5(object sender, EventArgs e)
228
238
{
229
239
if ( port != null ) port . Send ( "G1 Z5 F6000" ) ;
230
240
}
241
+
242
+ private void SetBound ( object sender , EventArgs e )
243
+ {
244
+ var tag = ( ( ToolStripMenuItem ) sender ) . Tag as string ;
245
+
246
+ float ? current = null ;
247
+ if ( tag . StartsWith ( "L" ) ) current = LowerBound ;
248
+ else current = UpperBound ;
249
+
250
+ string input = Microsoft . VisualBasic . Interaction . InputBox ( $ "Choose a { tag } Bound for color selection. Leave blank to reset to automatic bound. This is for visualization only (to match against subsequent scans).", $ "Set { tag } Color Bound", current ? . ToString ( ) ?? "" ) ;
251
+
252
+ if ( string . IsNullOrWhiteSpace ( input ) )
253
+ {
254
+ if ( tag . StartsWith ( "L" ) ) LowerBound = null ;
255
+ else UpperBound = null ;
256
+ }
257
+ else if ( float . TryParse ( input , out float value ) )
258
+ {
259
+ if ( tag . StartsWith ( "L" ) ) LowerBound = value ;
260
+ else UpperBound = value ;
261
+ }
262
+
263
+ bedPicture . Invalidate ( ) ;
264
+ }
231
265
}
232
266
}
0 commit comments