public void VisualInstruction_AskToChangeAddress(VisualInstructionUserControl sender) { if (!sender.IsAllOperandsOk()) { MessageBox.Show("Please, assign an address first!", "Change configuration", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } ChangeTimerCounterParametersForm changeTimerCounterParametersForm = new ChangeTimerCounterParametersForm(sender.OpCode); OutputBoxInstruction outputBox = ((OutputBoxInstruction)sender.Instruction); changeTimerCounterParametersForm.Type = outputBox.GetBoxType(); changeTimerCounterParametersForm.Preset = outputBox.GetPreset(); changeTimerCounterParametersForm.Accumulated = outputBox.GetAccumulated(); if (sender.OpCode.Equals(OperationCode.Timer)) { changeTimerCounterParametersForm.TimeBase = ((TimerInstruction)outputBox).GetTimeBase(); } DialogResult result = changeTimerCounterParametersForm.ShowDialog(); if (result == DialogResult.OK) { outputBox = (OutputBoxInstruction)sender.Instruction; outputBox.setBoxType(changeTimerCounterParametersForm.Type); outputBox.setPreset(changeTimerCounterParametersForm.Preset); outputBox.setAccumulated(changeTimerCounterParametersForm.Accumulated); switch (sender.OpCode) { case OperationCode.Timer: ((TimerInstruction)outputBox).SetTimeBase(changeTimerCounterParametersForm.TimeBase); sender.GetAddress().Timer.Type = changeTimerCounterParametersForm.Type; sender.GetAddress().Timer.Preset = changeTimerCounterParametersForm.Preset; sender.GetAddress().Timer.Accumulated = changeTimerCounterParametersForm.Accumulated; sender.GetAddress().Timer.TimeBase = changeTimerCounterParametersForm.TimeBase; break; case OperationCode.Counter: CounterInstruction counter = ((CounterInstruction)outputBox); counter.Counter.Type = changeTimerCounterParametersForm.Type; counter.Counter.Preset = changeTimerCounterParametersForm.Preset; counter.Counter.Accumulated = changeTimerCounterParametersForm.Accumulated; break; } sender.Invalidate(); } }
void VisualInstruction_Click(object sender, MouseEventArgs e) { if (!e.Button.Equals(MouseButtons.Right)) { return; } VisualInstructionUserControl visualInstruction = (VisualInstructionUserControl)sender; OperationCode opCode = visualInstruction.OpCode; if (opCode != OperationCode.LineBegin) { ladderForm.mnuInsertLadderLine.Enabled = false; ladderForm.mnuToggleBit.Enabled = false; if (opCode == OperationCode.ParallelBranchBegin || opCode == OperationCode.ParallelBranchEnd || opCode == OperationCode.ParallelBranchNext) { ladderForm.mnuAddressing.Enabled = false; ladderForm.mnuAddressing.Visible = false; ladderForm.mnuExtendParallelBranchAbove.Enabled = true; ladderForm.mnuExtendParallelBranchAbove.Visible = true; ladderForm.mnuExtendParallelBranchBelow.Enabled = true; ladderForm.mnuExtendParallelBranchBelow.Visible = true; } else { ladderForm.mnuAddressing.Enabled = true; ladderForm.mnuAddressing.Visible = true; if (visualInstruction.IsAllOperandsOk()) { ladderForm.mnuToggleBit.Enabled = true; } else { ladderForm.mnuToggleBit.Enabled = false; } ProjectForm projectForm = ladderForm.projectForm; TreeNode addressingNode = projectForm.tvnProjectTree.Nodes["tvnProjectNode"].Nodes["tvnAddressingNode"]; foreach (TreeNode eachAddressTypeNode in addressingNode.Nodes) { ToolStripMenuItem menu = null; switch (eachAddressTypeNode.Text) { case "Memories": menu = ladderForm.mnuMemory; break; case "Timer": menu = ladderForm.mnuTimer; break; case "Counter": menu = ladderForm.mnuCounter; break; case "Input": menu = ladderForm.mnuInput; break; case "Output": menu = ladderForm.mnuOutput; break; } Address address = null; if (visualInstruction.IsAllOperandsOk()) { Object obj = visualInstruction.GetOperand(0); if (obj is Address) { address = (Address)obj; } } menu.DropDownItems.Clear(); foreach (TreeNode eachAddressNode in eachAddressTypeNode.Nodes) { menu.DropDownItems.Add(eachAddressNode.Text); if (address != null) { if (address.GetName() == eachAddressNode.Text) { menu.DropDownItems[menu.DropDownItems.Count - 1].Select(); } } menu.DropDownItems[menu.DropDownItems.Count - 1].Name = eachAddressNode.Text; menu.DropDownItems[menu.DropDownItems.Count - 1].Tag = eachAddressNode.Tag; menu.DropDownItems[menu.DropDownItems.Count - 1].Click += new EventHandler(MenuContextAddress_Click); } } } } ladderForm.mnuContextAtInstruction.Show(visualInstruction.PointToScreen(e.Location)); }