Пример #1
0
        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();
            }
        }
Пример #2
0
        private void ResizeVisualInstructions()
        {
            tabStop++;
            LineBegin.TabIndex = tabStop;
            LineBegin.TabStop  = true;

            int outputToInsertIndex = 0;

            if (visualOutputInstructions.Count > 0)
            {
                outputToInsertIndex = visualInstructions.Count;
                visualInstructions.AddRange(visualOutputInstructions);
            }

            int index = 0;

            foreach (VisualInstructionUserControl visualInstruction in visualInstructions)
            {
                tabStop++;
                visualInstruction.TabIndex = tabStop;
                visualInstruction.TabStop  = true;

                visualInstruction.Size = new Size(Convert.ToInt32(Convert.ToDouble(visualInstruction.XYSize.Width) * percentageVisualInstructionReduction), visualInstruction.XYSize.Height);

                if (index >= outputToInsertIndex && (visualOutputInstructions.Count > 0))
                {
                    visualInstruction.Location = new Point(visualInstruction.XYPosition.X + (visualInstruction.XYSize.Width - (Convert.ToInt32(Convert.ToDouble(visualInstruction.XYSize.Width) * percentageVisualInstructionReduction))) / 2 + XPositionToFirstOutputVisualInstruction, visualInstruction.XYPosition.Y);
                }
                else
                {
                    visualInstruction.Location = new Point(visualInstruction.XYPosition.X + (visualInstruction.XYSize.Width - (Convert.ToInt32(Convert.ToDouble(visualInstruction.XYSize.Width) * percentageVisualInstructionReduction))) / 2, visualInstruction.XYPosition.Y);
                }

                visualInstruction.Visible = true;
                visualInstruction.Invalidate();
                index++;
            }

            if (visualOutputInstructions.Count > 0)
            {
                visualInstructions.RemoveRange(outputToInsertIndex, visualOutputInstructions.Count);
            }

            LineEnd.TabIndex = 0;
            LineEnd.TabStop  = false;

            BackgroundLine.TabIndex = 0;
            BackgroundLine.TabStop  = false;
            BackgroundLine.Invalidate();
        }