UniCB DrShp, AltStrings, double Press, new Cfg style, Lbl,Setp,Msrd pos != 0, arrow keys, refactorization, ver. 3.1.1597
This commit is contained in:
@@ -121,6 +121,7 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
|
||||
drawingCtrl.Route = 0;
|
||||
drawingCtrl.MeasuredValues = new double[measuredValuesCount];
|
||||
drawingCtrl.AltStrings = new string[measuredValuesCount];
|
||||
drawingCtrl.Setpoints = new double[setpointsCount];
|
||||
|
||||
drawingCtrl.SupressRedraws = false;
|
||||
@@ -418,25 +419,93 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
return --orient;
|
||||
}
|
||||
|
||||
///
|
||||
/// Moving items on the screen
|
||||
///
|
||||
/// Either on-screen left/right/up/down buttons (xyzButton_click handlers)
|
||||
/// or up/down/left/right arrow keys on the keyboard can be used.
|
||||
/// Step size (small or large) can eb switched over by Shift and Ctrl keys.
|
||||
/// Shit button selects large steps.
|
||||
/// Ctrl key selects small step.
|
||||
///
|
||||
static bool isLargeStep = false;
|
||||
///
|
||||
private void leftButton_Click(object sender, EventArgs e) { StepLeft(isLargeStep); }
|
||||
private void rightButton_Click(object sender, EventArgs e) { StepRight(isLargeStep); }
|
||||
private void upButton_Click(object sender, EventArgs e) { StepUp(isLargeStep); }
|
||||
private void downButton_Click(object sender, EventArgs e) { StepDown(isLargeStep); }
|
||||
///
|
||||
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||
{
|
||||
if (!unlocked)
|
||||
return base.ProcessCmdKey(ref msg, keyData); /// Do not process a key if not unlocked
|
||||
|
||||
if (keyData == Keys.Up) StepUp(isLargeStep); /// Process Up arrow key
|
||||
else if (keyData == Keys.Down) StepDown(isLargeStep); /// Process Down arrow key
|
||||
else if (keyData == Keys.Left) StepLeft(isLargeStep); /// Process Left arrow key
|
||||
else if (keyData == Keys.Right) StepRight(isLargeStep); /// Process Right arrow key
|
||||
else
|
||||
{
|
||||
if ((keyData & Keys.Shift) != 0)
|
||||
{
|
||||
isLargeStepLabel.Visible = isLargeStep = true;
|
||||
}
|
||||
|
||||
if ((keyData & Keys.Control) != 0)
|
||||
{
|
||||
isLargeStepLabel.Visible = isLargeStep = false;
|
||||
}
|
||||
|
||||
return base.ProcessCmdKey(ref msg, keyData); /// Return in case of non-arrow keys
|
||||
}
|
||||
|
||||
return true; /// Return (true) after an arrow key
|
||||
}
|
||||
|
||||
void StepLeft(bool large = false)
|
||||
{
|
||||
if (drawingCtrl.SelectedItem == null) return;
|
||||
IDrawingItem item = drawingCtrl.SelectedItem;
|
||||
if (item == null) return;
|
||||
int m = large ? 8 : 1;
|
||||
switch (drawingCtrl.SelectedElement)
|
||||
{
|
||||
case Element.Body:
|
||||
drawingCtrl.SelectedItem.X -= m * SchematicDrawing.Const.GridSize;
|
||||
if (drawingCtrl.SelectedItem.X < 0) drawingCtrl.SelectedItem.X = 0;
|
||||
item.X -= m * SchematicDrawing.Const.GridSize;
|
||||
if (item.X < 0) item.X = 0;
|
||||
break;
|
||||
case Element.Label:
|
||||
drawingCtrl.SelectedItem.LblX -= m;
|
||||
if (item is IDrawingItemWithMeasuredVal &&
|
||||
(item.Shape == Shape.TempM || item.Shape == Shape.PressM || item.Shape == Shape.Ambient))
|
||||
{
|
||||
/// Move measured value together with the label, keep label nearby the (nonexisting) body
|
||||
if (!large && item.LblX > 0)
|
||||
{
|
||||
item.LblX--;
|
||||
(item as IDrawingItemWithMeasuredVal).MsrdX--;
|
||||
}
|
||||
else if (!large && item.X >= SchematicDrawing.Const.GridSize)
|
||||
{
|
||||
item.X -= SchematicDrawing.Const.GridSize;
|
||||
item.LblX += (SchematicDrawing.Const.GridSize - 1);
|
||||
(item as IDrawingItemWithMeasuredVal).MsrdX += (SchematicDrawing.Const.GridSize - 1);
|
||||
}
|
||||
else if (item.X >= SchematicDrawing.Const.GridSize)
|
||||
{
|
||||
item.X -= SchematicDrawing.Const.GridSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Body exists, move just the label
|
||||
item.LblX -= m;
|
||||
}
|
||||
break;
|
||||
case Element.MeasuredVal:
|
||||
var msrdValItem = drawingCtrl.SelectedItem as IDrawingItemWithMeasuredVal;
|
||||
var msrdValItem = item as IDrawingItemWithMeasuredVal;
|
||||
if (msrdValItem != null) msrdValItem.MsrdX -= m;
|
||||
break;
|
||||
case Element.Setpoint:
|
||||
var setpointItem = drawingCtrl.SelectedItem as IDrawingItemWithSetpoint;
|
||||
var setpointItem = item as IDrawingItemWithSetpoint;
|
||||
if (setpointItem != null) setpointItem.SetpX -= m;
|
||||
break;
|
||||
default:
|
||||
@@ -448,22 +517,47 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
|
||||
void StepRight(bool large = false)
|
||||
{
|
||||
if (drawingCtrl.SelectedItem == null) return;
|
||||
IDrawingItem item = drawingCtrl.SelectedItem;
|
||||
if (item == null) return;
|
||||
int m = large ? 8 : 1;
|
||||
switch (drawingCtrl.SelectedElement)
|
||||
{
|
||||
case Element.Body:
|
||||
drawingCtrl.SelectedItem.X += m * SchematicDrawing.Const.GridSize;
|
||||
item.X += m * SchematicDrawing.Const.GridSize;
|
||||
break;
|
||||
case Element.Label:
|
||||
drawingCtrl.SelectedItem.LblX += m;
|
||||
if (item is IDrawingItemWithMeasuredVal &&
|
||||
(item.Shape == Shape.TempM || item.Shape == Shape.PressM || item.Shape == Shape.Ambient))
|
||||
{
|
||||
/// Move measured value together with the label, keep label nearby the (nonexisting) body
|
||||
if (!large && item.LblX < SchematicDrawing.Const.GridSize - 1)
|
||||
{
|
||||
item.LblX++;
|
||||
(item as IDrawingItemWithMeasuredVal).MsrdX++;
|
||||
}
|
||||
else if (!large)
|
||||
{
|
||||
item.X += SchematicDrawing.Const.GridSize;
|
||||
item.LblX -= (SchematicDrawing.Const.GridSize - 1);
|
||||
(item as IDrawingItemWithMeasuredVal).MsrdX -= (SchematicDrawing.Const.GridSize - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.X += SchematicDrawing.Const.GridSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Body exists, move just the label
|
||||
item.LblX += m;
|
||||
}
|
||||
break;
|
||||
case Element.MeasuredVal:
|
||||
var msrdValItem = drawingCtrl.SelectedItem as IDrawingItemWithMeasuredVal;
|
||||
var msrdValItem = item as IDrawingItemWithMeasuredVal;
|
||||
if (msrdValItem != null) msrdValItem.MsrdX += m;
|
||||
break;
|
||||
case Element.Setpoint:
|
||||
var setpointItem = drawingCtrl.SelectedItem as IDrawingItemWithSetpoint;
|
||||
var setpointItem = item as IDrawingItemWithSetpoint;
|
||||
if (setpointItem != null) setpointItem.SetpX += m;
|
||||
break;
|
||||
default:
|
||||
@@ -475,23 +569,48 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
|
||||
void StepUp(bool large = false)
|
||||
{
|
||||
if (drawingCtrl.SelectedItem == null) return;
|
||||
IDrawingItem item = drawingCtrl.SelectedItem;
|
||||
if (item == null) return;
|
||||
int m = large ? 8 : 1;
|
||||
switch (drawingCtrl.SelectedElement)
|
||||
{
|
||||
case Element.Body:
|
||||
drawingCtrl.SelectedItem.Y -= m * SchematicDrawing.Const.GridSize;
|
||||
if (drawingCtrl.SelectedItem.Y < 0) drawingCtrl.SelectedItem.Y = 0;
|
||||
item.Y -= m * SchematicDrawing.Const.GridSize;
|
||||
if (item.Y < 0) item.Y = 0;
|
||||
break;
|
||||
case Element.Label:
|
||||
drawingCtrl.SelectedItem.LblY -= m;
|
||||
if (item is IDrawingItemWithMeasuredVal &&
|
||||
(item.Shape == Shape.TempM || item.Shape == Shape.PressM || item.Shape == Shape.Ambient))
|
||||
{
|
||||
/// Move measured value together with the label, keep label nearby the (nonexisting) body
|
||||
if (!large && item.LblY > 0)
|
||||
{
|
||||
item.LblY--;
|
||||
(item as IDrawingItemWithMeasuredVal).MsrdY--;
|
||||
}
|
||||
else if (!large && item.Y >= SchematicDrawing.Const.GridSize)
|
||||
{
|
||||
item.Y -= SchematicDrawing.Const.GridSize;
|
||||
item.LblY += (SchematicDrawing.Const.GridSize - 1);
|
||||
(item as IDrawingItemWithMeasuredVal).MsrdY += (SchematicDrawing.Const.GridSize - 1);
|
||||
}
|
||||
else if (item.Y >= SchematicDrawing.Const.GridSize)
|
||||
{
|
||||
item.Y -= SchematicDrawing.Const.GridSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Body exists, move just the label
|
||||
item.LblY -= m;
|
||||
}
|
||||
break;
|
||||
case Element.MeasuredVal:
|
||||
var msrdValItem = drawingCtrl.SelectedItem as IDrawingItemWithMeasuredVal;
|
||||
var msrdValItem = item as IDrawingItemWithMeasuredVal;
|
||||
if (msrdValItem != null) msrdValItem.MsrdY -= m;
|
||||
break;
|
||||
case Element.Setpoint:
|
||||
var setpointItem = drawingCtrl.SelectedItem as IDrawingItemWithSetpoint;
|
||||
var setpointItem = item as IDrawingItemWithSetpoint;
|
||||
if (setpointItem != null) setpointItem.SetpY -= m;
|
||||
break;
|
||||
default:
|
||||
@@ -503,21 +622,47 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
|
||||
void StepDown(bool large = false)
|
||||
{
|
||||
if (drawingCtrl.SelectedItem == null) return;
|
||||
IDrawingItem item = drawingCtrl.SelectedItem;
|
||||
if (item == null) return;
|
||||
int m = large ? 8 : 1;
|
||||
switch (drawingCtrl.SelectedElement)
|
||||
{
|
||||
case Element.Body:
|
||||
drawingCtrl.SelectedItem.Y += m * SchematicDrawing.Const.GridSize;
|
||||
item.Y += m * SchematicDrawing.Const.GridSize;
|
||||
break;
|
||||
case Element.Label:
|
||||
drawingCtrl.SelectedItem.LblY += m; break;
|
||||
if (item is IDrawingItemWithMeasuredVal &&
|
||||
(item.Shape == Shape.TempM || item.Shape == Shape.PressM || item.Shape == Shape.Ambient))
|
||||
{
|
||||
/// Move measured value together with the label, keep label nearby the (nonexisting) body
|
||||
if (!large && item.LblY < SchematicDrawing.Const.GridSize - 1)
|
||||
{
|
||||
item.LblY++;
|
||||
(item as IDrawingItemWithMeasuredVal).MsrdY++;
|
||||
}
|
||||
else if (!large)
|
||||
{
|
||||
item.Y += SchematicDrawing.Const.GridSize;
|
||||
item.LblY -= (SchematicDrawing.Const.GridSize - 1);
|
||||
(item as IDrawingItemWithMeasuredVal).MsrdY -= (SchematicDrawing.Const.GridSize - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Y += SchematicDrawing.Const.GridSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Body exists, move just the label
|
||||
item.LblY += m;
|
||||
}
|
||||
break;
|
||||
case Element.MeasuredVal:
|
||||
var msrdValItem = drawingCtrl.SelectedItem as IDrawingItemWithMeasuredVal;
|
||||
var msrdValItem = item as IDrawingItemWithMeasuredVal;
|
||||
if (msrdValItem != null) msrdValItem.MsrdY += m;
|
||||
break;
|
||||
case Element.Setpoint:
|
||||
var setpointItem = drawingCtrl.SelectedItem as IDrawingItemWithSetpoint;
|
||||
var setpointItem = item as IDrawingItemWithSetpoint;
|
||||
if (setpointItem != null) setpointItem.SetpY += m;
|
||||
break;
|
||||
default:
|
||||
@@ -527,29 +672,9 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
drawingCtrl.Redraw();
|
||||
}
|
||||
|
||||
private void leftButton_Click(object sender, EventArgs e) { StepLeft((Control.ModifierKeys & Keys.Shift) != 0); }
|
||||
private void rightButton_Click(object sender, EventArgs e) { StepRight((Control.ModifierKeys & Keys.Shift) != 0); }
|
||||
private void upButton_Click(object sender, EventArgs e) { StepUp((Control.ModifierKeys & Keys.Shift) != 0); }
|
||||
private void downButton_Click(object sender, EventArgs e) { StepDown((Control.ModifierKeys & Keys.Shift) != 0); }
|
||||
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
int a = 5;
|
||||
|
||||
//Keys keyData = e.KeyData;
|
||||
//bool isLarge = (Control.ModifierKeys & Keys.Shift) != 0;
|
||||
//switch (keyData)
|
||||
//{
|
||||
// case Keys.Left: StepLeft(isLarge); return;
|
||||
// case Keys.Right: StepRight(isLarge); return;
|
||||
// case Keys.Up: StepUp(isLarge); return;
|
||||
// case Keys.Down: StepDown(isLarge); return;
|
||||
// default:
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
///
|
||||
/// Rotating and flipping items on the screen
|
||||
///
|
||||
private void cwButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (drawingCtrl.SelectedItem == null) return;
|
||||
@@ -574,7 +699,7 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
UpdateTitle();
|
||||
drawingCtrl.Redraw();
|
||||
}
|
||||
|
||||
///
|
||||
private void ccwButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (drawingCtrl.SelectedItem == null) return;
|
||||
@@ -599,7 +724,7 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
UpdateTitle();
|
||||
drawingCtrl.Redraw();
|
||||
}
|
||||
|
||||
///
|
||||
private void mirrorButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (drawingCtrl.SelectedItem != null && drawingCtrl.SelectedElement == Element.Body)
|
||||
@@ -610,10 +735,11 @@ namespace TBF.UI.Bench.EditSchDrawing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Rotates enum Sz values in selectedItem.Sz variable as follows:
|
||||
/// S -> M -> L -> XL -> S ...
|
||||
/// K1 -> K2 -> K3 -> K4 -> K5 -> K6 -> K7 -> K1 ...
|
||||
/// Changes enum Sz values in selectedItem.Sz variable as follows:
|
||||
/// S -> M -> L -> XL -> S ...
|
||||
/// K1 -> K2 -> K3 -> K4 -> K5 -> K6 -> K7 -> K1 ...
|
||||
/// </summary>
|
||||
private void sizeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user