RsMoveInstruction FindRelatedMoveInstruction(RsActionInstruction setBrushInstr) { var path = (RsPathProcedure)setBrushInstr.Parent; int idx = path.Instructions.IndexOf(setBrushInstr); return(path.Instructions.Where((mi, i) => i > idx).OfType <RsMoveInstruction>().Where(m => m.GetToTarget() != null).FirstOrDefault()); }
public static RsActionInstruction CreateSetBrush(RsMoveInstruction insertBefore, Axis axis, int value, string brushNum) { //:TODO: Check that SetBrush template is available? var path = (RsPathProcedure)insertBefore.Parent; var task = (RsTask)path.Parent; int index = path.Instructions.IndexOf(insertBefore); var ai = new RsActionInstruction(task, "SetBrush", axis.ToString()); ai.InstructionArguments[axis.ToString()].Value = value.ToString(); ai.InstructionArguments["BrushNumber"].Value = brushNum; path.Instructions.Insert(index, ai); return(ai); }
public static Tuple <Axis, RsInstructionArgument> GetBrushEventPosition(RsActionInstruction instr) { var x = instr.InstructionArguments["X"]; if (x != null && x.Enabled) { return(Tuple.Create(Axis.X, x)); } var y = instr.InstructionArguments["Y"]; if (y != null && y.Enabled) { return(Tuple.Create(Axis.Y, y)); } var z = instr.InstructionArguments["Z"]; if (z != null && z.Enabled) { return(Tuple.Create(Axis.Z, z)); } throw new ArgumentException(); }
public override void Update(VrUpdateArgs args) { var session = args.Session; DeleteBrushTempGfx(); var input = session.SemanticInput(); if (_trackedBrushInstruction != null) { if (input.IsSelectPressed) { // Drag brush var relatedMI = FindRelatedMoveInstruction(_trackedBrushInstruction); if (relatedMI != null) { Matrix4 wobjMat = relatedMI.GetWorkObject().ObjectFrame.GlobalMatrix; Vector3 point = wobjMat.InverseRigid().MultiplyPoint(session.RightController.PointerTransform.Translation); var pos = PathEditingHelper.GetBrushEventPosition(_trackedBrushInstruction); string val = ((int)(point[(int)pos.Item1 - 1] * 1000)).ToString(); if (val != pos.Item2.Value) { WithUndoAppend("VR Move SetBrush", () => { pos.Item2.Value = val; }); } _brushSelector.Caption = _trackedBrushInstruction.DisplayName; } return; } } var hitObj = GetHitObject(session.RightController.PointerTransform.Translation); var trackedMoveInstruction = hitObj?.Item1 as RsMoveInstruction; if (trackedMoveInstruction != null) { //:TODO: Supported for PaintC?? if (trackedMoveInstruction.Name != "PaintL" && trackedMoveInstruction.Name != "PaintC" || trackedMoveInstruction.GetToTarget() == null) { trackedMoveInstruction = null; } } var trackedBrushInstr = hitObj?.Item1 as RsActionInstruction; if (trackedBrushInstr != null && !string.Equals(trackedBrushInstr.Name, "SetBrush", StringComparison.OrdinalIgnoreCase)) { trackedBrushInstr = null; } if (trackedMoveInstruction != _trackedMoveInstruction) { _trackedMoveInstruction = trackedMoveInstruction; if (_brushSelector == null) { _brushSelector = new VrScrollSelector(session.RightController, "", _brushValues, _lastBrushNum); } _brushSelector.Caption = (_trackedMoveInstruction != null) ? "Add SetBrush" : "Brush Number"; } else if (trackedBrushInstr != _trackedBrushInstruction || _brushSelector == null) { if (_brushSelector != null) { _brushSelector.Dispose(); } _trackedBrushInstruction = trackedBrushInstr; if (_trackedBrushInstruction != null) { var numarg = _trackedBrushInstruction.InstructionArguments["BrushNumber"]; _brushSelector = new VrScrollSelector(session.RightController, _trackedBrushInstruction.DisplayName, _brushValues, numarg.Value); } else { _brushSelector = new VrScrollSelector(session.RightController, (_trackedMoveInstruction != null) ? "Add SetBrush" : "Brush Number", _brushValues, _lastBrushNum); } } if (_trackedBrushInstruction != null && input.DeleteClick) { var path = (RsPathProcedure)_trackedBrushInstruction.Parent; WithUndo("VR Delete SetBrush", () => { path.Instructions.Remove(_trackedBrushInstruction); }); _trackedBrushInstruction = null; return; } bool brushNumUpdated = _brushSelector.Update(); if (brushNumUpdated) { _lastBrushNum = _brushSelector.SelectedValue; } if (_trackedMoveInstruction != null && _trackedBrushInstruction == null) { Matrix4 wobjMat = _trackedMoveInstruction.GetWorkObject().ObjectFrame.GlobalMatrix; CreateBrushPlanePreview(hitObj.Item2, wobjMat); if (input.SelectClick) { Vector3 point = wobjMat.InverseRigid().MultiplyPoint(hitObj.Item2); var axis = ComputeBrushAxis(); int val = (int)(point[(int)axis - 1] * 1000); WithUndo("VR Create SetBrush", () => { PathEditingHelper.CreateSetBrush( _trackedMoveInstruction, axis, val, _brushSelector.SelectedValue); } ); DeleteBrushTempGfx(); } } else if (_trackedBrushInstruction != null && brushNumUpdated) { var numarg = _trackedBrushInstruction.InstructionArguments["BrushNumber"]; WithUndo("VR Edit SetBrush", () => { numarg.Value = _brushSelector.SelectedValue; }); _brushSelector.Caption = _trackedBrushInstruction.DisplayName; } }