static SnapAction ScoreSnap(SnapAction sa1, SnapAction sa2) { int diffs = 0; if (sa1 != SnapAction.None) { diffs++; } if (sa2 != SnapAction.None) { diffs++; } switch (diffs) { default: return(SnapAction.None); case 1: return(SnapAction.Coordinate1); case 2: return(SnapAction.Coordinate2); } }
static SnapAction HardSnapPoint(ref Point pt) { double x = pt.X; double y = pt.Y; SnapAction sa1 = HardSnapCoordinate(ref x); SnapAction sa2 = HardSnapCoordinate(ref y); pt = new Point(x, y); return(ScoreSnap(sa1, sa2)); }
public override uint KeyDown(KeyEventArgs e, GL_ControlBase control) { TransformChangeInfos transformChangeInfos = new TransformChangeInfos(new List <TransformChangeInfo>()); uint var = 0; bool selectionHasChanged = false; if ((CurrentAction != NoAction || ExclusiveAction != NoAction) && e.KeyCode != Keys.V) { CurrentAction.KeyDown(e); ExclusiveAction.KeyDown(e); var = NO_CAMERA_ACTION | REDRAW; } else if (e.KeyCode == Keys.Z) //focus camera on the selection { if (e.Control) { Undo(); } else { BoundingBox box = BoundingBox.Default; foreach (IEditableObject obj in GetObjects()) { obj.GetSelectionBox(ref box); } if (box != BoundingBox.Default) { control.CameraTarget = box.GetCenter(); } } var = REDRAW_PICKING; } else if (e.KeyCode == Keys.Y && e.Control) { Redo(); var = REDRAW_PICKING; } else if (e.KeyCode == Keys.H) //hide/show selected objects { foreach (IEditableObject obj in GetObjects()) { if (obj.IsSelected()) { obj.Visible = e.Shift; } } var = REDRAW_PICKING; } else if (e.KeyCode == Keys.S && e.Shift) //auto snap selected objects { SnapAction action = new SnapAction(); foreach (IEditableObject obj in GetObjects()) { obj.ApplyTransformActionToSelection(action, ref transformChangeInfos); } var = REDRAW_PICKING; } else if (e.KeyCode == Keys.R && e.Shift && e.Control) //reset scale for selected objects { ResetScale action = new ResetScale(); foreach (IEditableObject obj in GetObjects()) { obj.ApplyTransformActionToSelection(action, ref transformChangeInfos); } var = REDRAW_PICKING; } else if (e.KeyCode == Keys.R && e.Shift) //reset rotation for selected objects { ResetRot action = new ResetRot(); foreach (IEditableObject obj in GetObjects()) { obj.ApplyTransformActionToSelection(action, ref transformChangeInfos); } var = REDRAW_PICKING; } else if (e.Control && e.KeyCode == Keys.A) //select/deselect all objects { if (e.Shift) { foreach (IEditableObject obj in GetObjects()) { obj.DeselectAll(control); } selectionHasChanged = true; } if (!e.Shift && multiSelect) { foreach (IEditableObject obj in GetObjects()) { obj.SelectAll(control); } selectionHasChanged = true; } var = REDRAW; } foreach (IEditableObject obj in GetObjects()) { var |= obj.KeyDown(e, control); } foreach (AbstractGlDrawable obj in StaticObjects) { var |= obj.KeyDown(e, control); } if (selectionHasChanged) { UpdateSelection(var); } AddTransformToUndo(transformChangeInfos); return(var); }
public override uint KeyDown(KeyEventArgs e, GL_ControlBase control, bool isRepeat) { TransformChangeInfos transformChangeInfos = new TransformChangeInfos(new List <TransformChangeInfo>()); uint var = 0; bool selectionHasChanged = false; if (!isRepeat) { if ((SelectionTransformAction != NoAction || CurrentAction != null)) { SelectionTransformAction.KeyDown(e); CurrentAction?.KeyDown(e); var = NO_CAMERA_ACTION | REDRAW; } else { if (e.KeyData == KS_Focus) { BoundingBox box = BoundingBox.Default; foreach (IEditableObject obj in GetObjects()) { obj.GetSelectionBox(ref box); } if (box != BoundingBox.Default) { control.CameraTarget = box.GetCenter(); } var = REDRAW_PICKING; } else if (e.KeyData == KS_Undo) { Undo(); var = REDRAW_PICKING; } else if (e.KeyData == KS_Redo) { Redo(); var = REDRAW_PICKING; } else if (e.KeyData == KS_Hide) { foreach (IEditableObject obj in GetObjects()) { if (obj.IsSelected()) { obj.Visible = false; } } var = REDRAW_PICKING; } else if (e.KeyData == KS_UnHide) { foreach (IEditableObject obj in GetObjects()) { if (obj.IsSelected()) { obj.Visible = true; } } var = REDRAW_PICKING; } else if (e.KeyData == KS_SnapSelected) { SnapAction action = new SnapAction(); foreach (IEditableObject obj in GetObjects()) { obj.ApplyTransformActionToSelection(action, ref transformChangeInfos); } var = REDRAW_PICKING; } else if (e.KeyData == KS_ResetRotation) { ResetRot action = new ResetRot(); foreach (IEditableObject obj in GetObjects()) { obj.ApplyTransformActionToSelection(action, ref transformChangeInfos); } var = REDRAW_PICKING; } else if (e.KeyData == KS_ResetScale) { ResetScale action = new ResetScale(); foreach (IEditableObject obj in GetObjects()) { obj.ApplyTransformActionToSelection(action, ref transformChangeInfos); } var = REDRAW_PICKING; } else if (e.KeyData == KS_DeSelectAll) { foreach (IEditableObject obj in GetObjects()) { obj.DeselectAll(control); } selectionHasChanged = true; var = REDRAW; } else if (e.KeyData == KS_SelectAll) { if (multiSelect) { foreach (IEditableObject obj in GetObjects()) { obj.SelectAll(control); } selectionHasChanged = true; } var = REDRAW; } } } foreach (IEditableObject obj in GetObjects()) { var |= obj.KeyDown(e, control, isRepeat); } foreach (AbstractGlDrawable obj in StaticObjects) { var |= obj.KeyDown(e, control, isRepeat); } if (selectionHasChanged) { UpdateSelection(var); } AddTransformToUndo(transformChangeInfos); return(var); }