Ejemplo n.º 1
0
        private DigitalDataPoint cellPointToDigitalDataPoint(Point p)
        {
            if (Storage.sequenceData != null)
            {
                TimeStep step = Storage.sequenceData.getNthDisplayedTimeStep(p.X);
                if (step == null)
                {
                    return(null);
                }

                int channelID = cellPointToChannelID(p);
                if (channelID == -1)
                {
                    return(null);
                }


                if (step.DigitalData.ContainsKey(channelID))
                {
                    return(step.DigitalData[channelID]);
                }
                else
                {
                    DigitalDataPoint newPoint = new DigitalDataPoint();
                    step.DigitalData.Add(channelID, newPoint);
                    return(newPoint);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        private void refreshAllContinueCellsInSameRow(Point p)
        {
            if (buffer == null)
            {
                return;
            }
            bool refreshedACell = false;

            using (Graphics g = Graphics.FromImage(buffer)) {
                if (g == null)
                {
                    return;
                }
                for (int i = 0; i < Storage.sequenceData.getNDisplayedTimeSteps(); i++)
                {
                    Point            newPoint = new Point(i, p.Y);
                    DigitalDataPoint dp       = cellPointToDigitalDataPoint(p);
                    if (dp.DigitalContinue)
                    {
                        refreshCell(g, newPoint);
                        refreshedACell = true;
                    }
                }
            }
            if (refreshedACell)
            {
                this.Refresh();
            }
        }
Ejemplo n.º 3
0
        private void colorHover(Point temp, Graphics g)
        {
            if (!invalidated)
            {
                g.FillRectangle(trueBrush(temp.Y), temp.X * colWidth + 10, temp.Y * rowHeight + 3, colWidth - 20, rowHeight - 6);

                Pen whitePen = Pens.White;

                // g.DrawLine(whitePen, 0, temp.Y * rowHeight, Width, temp.Y  * rowHeight);
                // g.DrawLine(whitePen, 0, (temp.Y +1)* rowHeight, Width, (temp.Y+1) * rowHeight);
                g.DrawLine(whitePen, temp.X * ColWidth, 0, temp.X * ColWidth, Height);
                g.DrawLine(whitePen, (temp.X + 1) * ColWidth, 0, (temp.X + 1) * ColWidth, Height);

                DigitalDataPoint dp = cellPointToDigitalDataPoint(temp);
                if (dp != null)
                {
                    if (dp.DigitalPulse != null)
                    {
                        paintPulse(g, temp, dp);
                    }
                }

                TimestepEditor te =
                    WordGenerator.MainClientForm.instance.sequencePage.getTimestepEditor(
                        Storage.sequenceData.getNthDisplayedTimeStep(temp.X));

                /*   Label chanLab = WordGenerator.mainClientForm.instance.sequencePage1.digitalChannelLabelsPanel1.channelLabels[temp.Y*2];
                 *
                 * if (oldChanLab != chanLab)
                 * {
                 *     if (oldChanLab != null)
                 *     {
                 *         oldChanLab.BorderStyle = BorderStyle.None;
                 *     }
                 *     chanLab.BorderStyle = BorderStyle.FixedSingle;
                 *
                 *     oldChanLab = chanLab;
                 * }
                 */

                if (oldTe != te)
                {
                    if (oldTe != null)
                    {
                        oldTe.BorderStyle = BorderStyle.None;
                    }
                    te.BorderStyle = BorderStyle.FixedSingle;
                    oldTe          = te;
                }


                /* preHoverColor = te.BackColor;
                 *
                 * te.BackColor = Color.Tan;
                 */
            }
        }
Ejemplo n.º 4
0
        private Point paintPulse(Graphics g, Point p, DigitalDataPoint dp)
        {
            painCellRectInternal(g, p, pulseOutlintPen);
            Brush textBrush = Brushes.White;

            if (!dp.getValue() && !dp.DigitalContinue)
            {
                textBrush = Brushes.Black;
            }
            g.DrawString(dp.DigitalPulse.PulseName, variableFont, textBrush, new Rectangle(p.X * colWidth + 2, p.Y * rowHeight + 2, colWidth - 4, rowHeight - 4));
            return(p);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles only right mouse clicks.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseClick(MouseEventArgs e)
        {
            if (!WordGenerator.MainClientForm.instance.lockDigitalCheckBox.Checked)
            {
                //         base.OnMouseClick(e);

                if (e.Button == MouseButtons.Right)
                {
                    if (Storage.sequenceData.DigitalPulses.Count != 0)
                    {
                        Point clickPoint = clickPixelToCellPoint(e.X, e.Y);

                        DigitalDataPoint dp = this.cellPointToDigitalDataPoint(clickPoint);
                        if (dp != null)
                        {
                            ComboBox pulseSelectBox = new ComboBox();
                            pulseSelectBox.DropDownStyle = ComboBoxStyle.DropDownList;
                            pulseSelectBox.Items.Clear();

                            pulseSelectBox.Items.Add("None.");
                            foreach (Pulse pulse in Storage.sequenceData.DigitalPulses)
                            {
                                if (pulse.pulseType == Pulse.PulseType.OldDigital)
                                {
                                    pulseSelectBox.Items.Add(pulse);
                                }
                            }
                            pulseSelectBox.Width    = colWidth;
                            pulseSelectBox.Height   = rowHeight;
                            pulseSelectBox.Location = cellPointToClickPixel(clickPoint.X, clickPoint.Y);

                            pulseSelector       = pulseSelectBox;
                            pulseSelectorTarget = dp;
                            pulseSelectorPoint  = clickPoint;

                            pulseSelector.Visible = true;

                            this.Controls.Add(pulseSelector);

                            pulseSelector.DropDownClosed += new EventHandler(pulseSelector_DropDownClosed);
                            pulseSelector.DroppedDown     = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        void pulseSelector_DropDownClosed(object sender, EventArgs e)
        {
            if (pulseSelectorTarget != null)
            {
                Pulse val = pulseSelector.SelectedItem as Pulse;
                pulseSelectorTarget.DigitalPulse = val;
            }
            this.Controls.Remove(pulseSelector);

            refreshCell(Graphics.FromImage(buffer), pulseSelectorPoint);

            pulseSelector.Dispose();
            pulseSelector       = null;
            pulseSelectorTarget = null;

            this.Invalidate();
            WordGenerator.MainClientForm.instance.sequencePage.updateAllPulseIndicators();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Fills a cell with appropriate brush based on its data, and writes variable names if under variable control.
        /// </summary>
        private void refreshCell(Graphics g, Point p)
        {
            DigitalDataPoint dp = cellPointToDigitalDataPoint(p);

            Pen outlinePen = normalOutlinePen;

            /* if (dp != null)
             * {
             *   if (dp.usesPulse())
             *   {
             *       outlinePen = pulseOutlintPen;
             *   }
             *   else
             *   {
             *       outlinePen = normalOutlinePen;
             *   }
             * }*/


            if (dp == null)
            {
                paintCell(g, p, nullBrush, outlinePen);
                return;
            }

            if (dp.variable == null)
            {
                Brush br;
                if (dp.DigitalContinue)
                {
                    int stepID    = cellPointToTimeStepId(p);
                    int channelID = cellPointToChannelID(p);
                    if (stepID == -1 || channelID == -1)
                    {
                        return;
                    }
                    TimeStep step          = Storage.sequenceData.TimeSteps[stepID];
                    bool     continueValue = step.getDigitalValue(channelID,
                                                                  Storage.sequenceData.TimeSteps,
                                                                  stepID);

                    br = continueBrush(p.Y, continueValue);
                }
                else if (dp.ManualValue)
                {
                    br = trueBrush(p.Y);
                    // paintCell(g, p, trueBrush(p.Y), outlinePen);
                }
                else
                {
                    br = falseBrush;
                    // paintCell(g, p, falseBrush, outlinePen);
                    //painCellRectInternal(g, p, new Pen(trueBrush(p.Y)));
                    //drawCellTopAndBottomInternalLines(g, p, new Pen(trueBrush(p.Y)));
                }
                paintCell(g, p, br, outlinePen);
            }
            else
            {
                // this will probably never get used. Though there is functionality for having a variable value for a digital
                // this does not get set anywhere. Probably this is superseeded by pulse capability
                paintCell(g, p, variableBrush, outlinePen);
                g.DrawString(dp.variable.ToString(), variableFont, Brushes.Black, new RectangleF(p.X * colWidth, p.Y * rowHeight, colWidth, rowHeight));
            }

            if (dp.DigitalPulse != null)
            {
                p = paintPulse(g, p, dp);
            }

            if (WordGenerator.MainClientForm.instance.studentEdition)
            {
                paintCell(g, p, seb, null);
            }
        }
Ejemplo n.º 8
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (!WordGenerator.MainClientForm.instance.lockDigitalCheckBox.Checked)
            {
                //          base.OnMouseUp(e);



                if (e.Button == MouseButtons.Left)
                {
                    bool useContinue = false;

                    if (CTRL_is_pressed())
                    {
                        useContinue = true;
                    }

                    if (mouseClicking)
                    {
                        mouseClicking = false;

                        int start = Math.Min(clickStartPoint.X, clickEndPoint.X);
                        int end   = Math.Max(clickStartPoint.X, clickEndPoint.X);


                        for (int col = start; col <= end; col++)
                        {
                            Point            p  = new Point(col, clickStartPoint.Y);
                            DigitalDataPoint dp = cellPointToDigitalDataPoint(p);
                            if (dp != null)
                            {
                                if (dp.variable == null)
                                {
                                    if (useContinue)
                                    {
                                        dp.DigitalContinue = true;
                                    }
                                    else
                                    {
                                        if (dp.DigitalContinue)
                                        {
                                            dp.DigitalContinue = false;
                                            dp.ManualValue     = false;
                                        }
                                        else
                                        {
                                            dp.ManualValue = !dp.ManualValue;
                                        }

                                        refreshAllContinueCellsInSameRow(p);
                                    }
                                }
                            }
                        }



                        drawDrag();

                        clickStartPoint = new Point(-1, -1);
                        clickEndPoint   = new Point(-1, -1);
                    }
                }
            }
        }
        /// <summary>
        /// Sets the dwell word of each channel to equal that channel's final value in the current sequence mode by creating (or overwriting) a 0s-long 'Rest values' initial timestep.
        /// </summary>
        private static void SetDwellWordByChannelFinalValue()
        {
            if (Storage.sequenceData != null)
            {
                //Here we will store the indices of all of the timesteps that are enabled
                //in this sequence mode
                List <int> indcs = new List <int>(Storage.sequenceData.TimeSteps.Count);

                for (int i = 0; i < Storage.sequenceData.TimeSteps.Count; i++)
                {
                    if (Storage.sequenceData.TimeSteps[i].StepEnabled)
                    {
                        indcs.Add(i);
                    }
                }

                //If a Rest values timestep already exists, we won't have to create a new
                //one later
                bool restValuesExists = false;
                if (indcs.Count > 0 && Storage.sequenceData.TimeSteps[indcs[0]].StepName == "Rest values")
                {
                    restValuesExists = true;
                }

                int last = 0;
                if (indcs.Count > 0)
                {
                    last = indcs.Count - 1;
                }

                //Now we will run through all of the analog and digital channels, and for
                //each one, store what the channel's value is at the end of the sequence.
                //To do so, we find the closest, non-continue timestep in the sequence
                //for each channel (if there are none, then that channel should not be
                //used during the sequence).
                int ind;
                Dictionary <int, double> analogDwellWords  = new Dictionary <int, double>();
                Dictionary <int, bool>   digitalDwellWords = new Dictionary <int, bool>();

                foreach (int id in Storage.settingsData.logicalChannelManager.Analogs.Keys)
                {
                    ind = last;
                    analogDwellWords.Add(id, 0);

                    //Loop until a channel's waveform is not null (i.e. it is not a 'Continue' timestep)
                    while (Storage.sequenceData.TimeSteps[indcs[ind]].getChannelWaveform(id) == null && ind >= 0)
                    {
                        ind--;
                    }

                    if (Storage.sequenceData.TimeSteps[indcs[ind]].getChannelWaveform(id) != null)
                    {
                        analogDwellWords[id] = Storage.sequenceData.TimeSteps[indcs[ind]].getChannelWaveform(id).getValueAtTime(Storage.sequenceData.TimeSteps[indcs[ind]].StepDuration.getBaseValue(), Storage.sequenceData.Variables, Storage.sequenceData.CommonWaveforms);
                    }
                }

                foreach (int id in Storage.settingsData.logicalChannelManager.Digitals.Keys)
                {
                    ind = last;
                    digitalDwellWords.Add(id, false);

                    while (Storage.sequenceData.TimeSteps[indcs[ind]].DigitalData[id].DigitalContinue == true && ind > 0)
                    {
                        ind--;
                    }

                    if (Storage.sequenceData.TimeSteps[indcs[ind]].DigitalData[id].DigitalContinue == false)
                    {
                        digitalDwellWords[id] = Storage.sequenceData.TimeSteps[indcs[ind]].DigitalData[id].ManualValue;
                    }
                }

                //If a 'Rest values' timestep does not already exist, create one and place it
                //at the beginning of the sequence so that it is the first timestep
                if (!restValuesExists)
                {
                    PulsesPage.CreateNewAnalogTimestep("Rest values", 0, true, true, false);
                }

                TimeStep step = Storage.sequenceData.TimeSteps[indcs[0]]; //step will be Rest values
                step.StepDuration.setBaseValue(0);

                //For each analog channel, the Rest value timestep's analog group will have
                //a linear waveform with one data point. The y-value will be the dwell value.
                foreach (int id in analogDwellWords.Keys)
                {
                    if (!step.AnalogGroup.containsChannelID(id))
                    {
                        step.AnalogGroup.addChannel(id);
                    }

                    step.AnalogGroup.ChannelDatas[id].ChannelEnabled             = true;
                    step.AnalogGroup.ChannelDatas[id].waveform.interpolationType = Waveform.InterpolationType.Linear;
                    step.AnalogGroup.ChannelDatas[id].waveform.XValues           = new List <DimensionedParameter>();
                    step.AnalogGroup.ChannelDatas[id].waveform.YValues           = new List <DimensionedParameter>();
                    step.AnalogGroup.ChannelDatas[id].waveform.XValues.Add(new DimensionedParameter(Units.s, 0));
                    step.AnalogGroup.ChannelDatas[id].waveform.YValues.Add(new DimensionedParameter(Units.V, analogDwellWords[id]));
                }

                //For each digital channel, set the Rest values timestep
                foreach (int id in digitalDwellWords.Keys)
                {
                    DigitalDataPoint dp = new DigitalDataPoint();
                    dp.DigitalContinue = false;
                    dp.ManualValue     = digitalDwellWords[id];
                    if (!step.DigitalData.ContainsKey(id))
                    {
                        step.DigitalData.Add(id, dp);
                    }
                    else
                    {
                        step.DigitalData[id] = dp;
                    }
                }

                MainClientForm.instance.RefreshSequenceDataToUI();
            }
        }