示例#1
0
        //extract neck button
        private void neck_extract(object sender, RoutedEventArgs e)
        {
            VirtualSurgeonPoint[] points = m_vs_wrapper.FindNeck();
            Point[] newp = new Point[points.Length];
            int     i    = 0;

            foreach (VirtualSurgeonPoint p in points)
            {
                newp.SetValue(new Point(p.x, p.y), i++);
            }
            image1.points        = newp;
            image1.UnderlayImage = myBitmapImage;
            image1.Init();
            image1.InvalidateVisual();
        }
示例#2
0
        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            
            try
            {
                if (e.CellValue != null)
                {
                    if (e.CellValue != DBNull.Value)
                    {
                        int b = 0;
                        int cellvalue = 0;
                        //if (m_isHexMode)
                        if (m_viewtype == SuiteViewType.Hexadecimal)
                        {
                            b = Convert.ToInt32(e.CellValue.ToString(), 16);
                            cellvalue = b;
                        }
                        else
                        {
                            b = Convert.ToInt32(e.CellValue.ToString());
                            cellvalue = b;
                        }
                        b *= 255;
                        if (m_MaxValueInTable != 0)
                        {
                            b /= m_MaxValueInTable;
                        }
                        int red = 128;
                        int green = 128;
                        int blue = 128;
                        Color c = Color.White;
                        if (m_OnlineMode)
                        {
                            b /= 2;
                            red = b;
                            if (red < 0) red = 0;
                            if (red > 255) red = 255;
                            if (b > 255) b = 255;
                            green = 255 - red;
                            blue = 255 - red;
                            c = Color.FromArgb(red, green, blue);
                            // if (b == 0) c = Color.Transparent;

                        }
                        else if (!m_isRedWhite)
                        {
                            red = b;
                            if (red < 0) red = 0;
                            if (red > 255) red = 255;
                            if (b > 255) b = 255;
                            blue = 0;
                            green = 255 - red;
                            c = Color.FromArgb(red, green, blue);
                        }
                        else
                        {
                            if (b < 0) b = -b;
                            if (b > 255) b = 255;
                            c = Color.FromArgb(b, Color.Red);
                        }
                        if (!m_disablecolors)
                        {
                            SolidBrush sb = new SolidBrush(c);
                            e.Graphics.FillRectangle(sb, e.Bounds);
                        }
                        if (m_viewtype == SuiteViewType.Easy )
                        {
                            float dispvalue = 0;
                            dispvalue = (float)cellvalue;
                            if (correction_offset != 0 || correction_factor != 1)
                            {
                                dispvalue = (float)((float)cellvalue * (float)correction_factor) + (float)correction_offset;
                                if (m_viewtype != SuiteViewType.Hexadecimal)
                                //if (!m_isHexMode)
                                {
                                    if (m_map_name.StartsWith("Ign_map_0!") || m_map_name.StartsWith("Ign_map_4!"))
                                    {
                                        e.DisplayText = dispvalue.ToString("F1") + "\u00b0";
                                        /*if (dispvalue < 0)
                                        {
                                            logger.Debug("Negative value:  " + cellvalue.ToString());

                                        }*/
                                    }
                                    else if (m_map_name.StartsWith("Reg_kon_mat"))
                                    {
                                        e.DisplayText = dispvalue.ToString("F0") + @"%";
                                    }
                                    else
                                    {
                                        e.DisplayText = dispvalue.ToString("F2");
                                    }
                                }
                                else
                                {
                                    //e.DisplayText = dispvalue.ToString();
                                }
                            }
                            else if (m_map_name.StartsWith("Reg_kon_mat"))
                            {
                                e.DisplayText = dispvalue.ToString("F0") + @"%";
                            }
                        }
                        //if (m_map_name == "BFuelCal.Map" || m_map_name == "IgnNormCal.Map" || m_map_name == "TargetAFR" || m_map_name == "FeedbackAFR" || m_map_name == "FeedbackvsTargetAFR")
                        if (X_axis_name.ToLower() == "mg/c" && Y_axis_name.ToLower() == "rpm")
                        {
                            
                            try
                            {
                                if (open_loop != null)
                                {
                                    int airmassvalue = GetXaxisValue(e.Column.AbsoluteIndex);
                                    int rpmvalue = GetYaxisValue(e.RowHandle);
                                    if (open_loop.Length > 0)
                                    {
                                        int mapopenloop = GetOpenLoopValue(e.RowHandle);
                                        if (mapopenloop > airmassvalue)
                                        {
                                            if (m_StandardFill == 0)
                                            {

                                            }
                                            else if (m_StandardFill == 1)
                                            {
                                                Pen p = new Pen(Brushes.Black, 2);
                                                e.Graphics.DrawRectangle(p, e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2);
                                                p.Dispose();
                                            }
                                            else
                                            {
                                                Point[] pnts = new Point[4];
                                                pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y), 0);
                                                pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width - (e.Bounds.Height / 2), e.Bounds.Y), 1);
                                                pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y + (e.Bounds.Height / 2)), 2);
                                                pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y), 3);
                                                e.Graphics.FillPolygon(Brushes.SeaGreen, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                                            }             
                                        }
                                    }
                                }
                            }
                            catch (Exception E)
                            {
                                logger.Debug(E.Message);
                            }

                        }
                    }
                }
                if (m_selectedrowhandle >= 0 && m_selectedcolumnindex >= 0)
                {
                    if (e.RowHandle == m_selectedrowhandle && e.Column.AbsoluteIndex == m_selectedcolumnindex)
                    {
                        SolidBrush sbsb = new SolidBrush(Color.Yellow);
                        e.Graphics.FillRectangle(sbsb, e.Bounds);
                    }
                }
            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }
        }
示例#3
0
        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            try
            {
                if (e.CellValue != null)
                {
                    if (e.CellValue != DBNull.Value)
                    {
                        int b = 0;
                        int cellvalue = 0;
                        //if (m_isHexMode)
                        b = Convert.ToInt32(e.CellValue.ToString());
                        cellvalue = b;
                        b *= 255;
                        if (m_MaxValueInTable != 0)
                        {
                            b /= m_MaxValueInTable;
                        }
                        int red = 128;
                        int green = 128;
                        int blue = 128;
                        Color c = Color.White;
                        red = b;
                        if (red < 0) red = 0;
                        if (red > 255) red = 255;
                        if (b > 255) b = 255;
                        blue = 0;
                        green = 255 - red;
                        c = Color.FromArgb(red, green, blue);
                        SolidBrush sb = new SolidBrush(c);
                        e.Graphics.FillRectangle(sb, e.Bounds);

                        // check limiter type
                        //limitermap
                        int row = rows - (e.RowHandle + 1);
                        limitType curLimit = (limitType)limitermap.GetValue((row * columns) + e.Column.AbsoluteIndex);
                        Point[] pnts = new Point[4];
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y), 0);
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width - (e.Bounds.Height / 2), e.Bounds.Y), 1);
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y + (e.Bounds.Height / 2)), 2);
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y), 3);
                        if (curLimit == limitType.AirmassLimiter)
                        {
                            e.Graphics.FillPolygon(Brushes.Blue, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TorqueLimiterEngineE85)
                        {
                            e.Graphics.FillPolygon(Brushes.Purple, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TorqueLimiterEngine)
                        {
                            e.Graphics.FillPolygon(Brushes.Yellow, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TurboSpeedLimiter)
                        {
                            e.Graphics.FillPolygon(Brushes.Black, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TorqueLimiterGear)
                        {
                            e.Graphics.FillPolygon(Brushes.SaddleBrown, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.FuelCutLimiter)
                        {
                            e.Graphics.FillPolygon(Brushes.DarkGray, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.OverBoostLimiter)
                        {
                            e.Graphics.FillPolygon(Brushes.CornflowerBlue, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TorqueLimiterEngineE85Auto)
                        {
                            e.Graphics.FillPolygon(Brushes.White, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        if (comboBoxEdit2.SelectedIndex == 1)
                        {
                            // convert airmass to torque
                            int rpm = Convert.ToInt32(x_axisvalues.GetValue(e.Column.AbsoluteIndex));
                            int torque;
                            if (displayTorqueInLBFT.Checked)
                            {
                                torque = AirmassToTorqueLbft(Convert.ToInt32(e.CellValue), rpm, useTrionicCalculationForTorque.Checked);
                                e.DisplayText = torque.ToString();
                            }
                            else
                            {
                                torque = AirmassToTorque(Convert.ToInt32(e.CellValue), rpm, useTrionicCalculationForTorque.Checked);
                            }
                            e.DisplayText = torque.ToString();
                        }
                        else if (comboBoxEdit2.SelectedIndex == 2)
                        {
                            //convert airmass to horsepower
                            int rpm = Convert.ToInt32(x_axisvalues.GetValue(e.Column.AbsoluteIndex));
                            int torque = AirmassToTorque(Convert.ToInt32(e.CellValue), rpm, useTrionicCalculationForTorque.Checked);
                            int horsepower = TorqueToPower(torque, rpm);
                            if (displayPowerInkW.Checked)
                            {
                                horsepower = TorqueToPowerkW(torque, rpm);
                            }
                            e.DisplayText = horsepower.ToString();
                        }
                        else if (comboBoxEdit2.SelectedIndex == 3) //injector DC
                        {
                            int rpm = Convert.ToInt32(x_axisvalues.GetValue(e.Column.AbsoluteIndex));
                            int injDC = CalculateInjectorDC(Convert.ToInt32(e.CellValue), rpm);
                            e.DisplayText = injDC.ToString();
                        }
                        else if (comboBoxEdit2.SelectedIndex == 4) //target lambda
                        {
                            int rpm = Convert.ToInt32(x_axisvalues.GetValue(e.Column.AbsoluteIndex));
                            int targetLambda = CalculateTargetLambda(Convert.ToInt32(e.CellValue), rpm);
                            float dtarget = (float)targetLambda;
                            dtarget /= 100;
                            e.DisplayText = dtarget.ToString("F2");

                        }
                        else if (comboBoxEdit2.SelectedIndex == 5) //target AFR
                        {
                            int rpm = Convert.ToInt32(x_axisvalues.GetValue(e.Column.AbsoluteIndex));
                            int targetLambda = CalculateTargetLambda(Convert.ToInt32(e.CellValue), rpm);
                            float dtarget = (float)targetLambda;
                            dtarget /= 100;
                            if (isFuelE85.Checked)
                            {
                                // E85
                                dtarget *= 9.76F;
                            }
                            else
                            {
                                dtarget *= 14.7F;
                            }
                            e.DisplayText = dtarget.ToString("F2");
                        }
                        else if (comboBoxEdit2.SelectedIndex == 6)
                        {
                            // convert to estimated EGT
                            int rpm = Convert.ToInt32(x_axisvalues.GetValue(e.Column.AbsoluteIndex));
                            int airmass = Convert.ToInt32(e.CellValue);
                            int egt = CalculateEstimateEGT(airmass, rpm);
                            e.DisplayText = egt.ToString();
                        }
                        else
                        {
                            int airmass = Convert.ToInt32(e.CellValue);
                            e.DisplayText = airmass.ToString();
                        }
                    }
                }
            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }
        }
示例#4
0
        void DrawDropLine(Graphics g, int index, bool drawLine, HitTestType hit)
        {
            Brush brush = null;
            Pen pen = null;
            try
            {
                if (drawLine)
                {
                    droppedPosition = index;
                    lastDrawnLineIndex = index;
                    brush = SystemBrushes.ControlText;
                    pen = SystemPens.ControlText;
                }
                else
                {
                    // If there is nothing painted, no need to erase
                    if (lastDrawnLineIndex == -1)
                        return;

                    index = lastDrawnLineIndex;
                    brush = new SolidBrush(bands[currentBandIndex].Background);
                    pen = new Pen(bands[currentBandIndex].Background);
                    lastDrawnLineIndex = -1;
                }

                int itemsCount = bands[currentBandIndex].Items.Count;
                Rectangle itemRect = GetItemRect(g, bands[currentBandIndex], index, Rectangle.Empty);

                Rectangle viewPortRect = GetViewPortRect();
                int y;
                if (bands[currentBandIndex].IconView == IconView.Small)
                    y = itemRect.Top - Y_SMALLICON_SPACING / 2;
                else
                    y = itemRect.Top - Y_LARGEICON_SPACING;

                if (hit == HitTestType.DropLineLastItem)
                {
                    // use the bottom of the label if dealing with the last item
                    Rectangle labelRect = GetLabelRect(itemsCount - 1);
                    y = labelRect.Bottom + Y_LARGEICON_SPACING;
                    paintedDropLineLastItem = true;
                    // the none existing item index
                    droppedPosition = itemsCount;
                }
                else if (paintedDropLineLastItem)
                {
                    Rectangle labelRect = GetLabelRect(itemsCount - 1);
                    y = labelRect.Bottom + Y_LARGEICON_SPACING;
                    paintedDropLineLastItem = false;
                }

                // If we are using a bitmap background, erase
                // by painting the portion of the bitmap background
                if (backgroundBitmap != null && lastDrawnLineIndex == -1)
                {
                    Rectangle rcStrip = new Rectangle(viewPortRect.Left, y - 6, viewPortRect.Width, 12);
                    g.DrawImage(backgroundBitmap, rcStrip, rcStrip, GraphicsUnit.Pixel);
                    return;
                }

                // Draw horizontal line
                Point p1 = new Point(viewPortRect.Left + 11, y);
                Point p2 = new Point(viewPortRect.Right - 11, y);
                g.DrawLine(pen, p1, p2);

                // Draw left triangle
                Point top;
                Point bottom;
                if (index == firstItem)
                    top = new Point(viewPortRect.Left + 5, y);
                else
                    top = new Point(viewPortRect.Left + 5, y - 6);

                if (hit == HitTestType.DropLineLastItem)
                    bottom = new Point(viewPortRect.Left + 5, y + 1);
                else
                    bottom = new Point(viewPortRect.Left + 5, y + 6);

                Point middle = new Point(viewPortRect.Left + 11, y);
                Point[] points = new Point[3];
                points.SetValue(top, 0);
                points.SetValue(middle, 1);
                points.SetValue(bottom, 2);
                g.FillPolygon(brush, points);

                // Draw right triangle
                if (index == firstItem)
                    top = new Point(viewPortRect.Right - 5, y);
                else
                    top = new Point(viewPortRect.Right - 5, y - 6);

                if (hit == HitTestType.DropLineLastItem)
                    bottom = new Point(viewPortRect.Right - 5, y + 1);
                else
                    bottom = new Point(viewPortRect.Right - 5, y + 6);

                middle = new Point(viewPortRect.Right - 11, y);
                points.SetValue(top, 0);
                points.SetValue(middle, 1);
                points.SetValue(bottom, 2);
                g.FillPolygon(brush, points);
            }
            finally
            {
                if (!drawLine)
                {
                    brush.Dispose();
                    pen.Dispose();
                }
            }
        }
示例#5
0
 //extract neck button
 private void neck_extract(object sender, RoutedEventArgs e)
 {
     VirtualSurgeonPoint[] points = m_vs_wrapper.FindNeck();
     Point[] newp = new Point[points.Length];
     int i = 0;
     foreach (VirtualSurgeonPoint p in points)
     {
         newp.SetValue(new Point(p.x, p.y), i++);
     }
     image1.points = newp;
     image1.UnderlayImage = myBitmapImage;
     image1.Init();
     image1.InvalidateVisual();
 }
示例#6
0
        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            //  if mapname is Insp_mat or Fuel_knock_map indicate open/closed loop operation
            // the map indicating where the ecu switches to open loop should be loaded into... 
            // for Fuel_knock_map this is Open_loop_knock!
            // for Insp_mat this is Open_loop!
            try
            {
                if (e.CellValue != null)
                {
                    if (e.CellValue != DBNull.Value)
                    {
                        int b = 0;
                        int cellvalue = 0;
                        //if (m_isHexMode)
                        if (m_viewtype == Trionic5Tools.ViewType.Hexadecimal)
                        {
                            b = Convert.ToInt32(e.CellValue.ToString(), 16);
                            cellvalue = b;
                        }
                        else
                        {
                            b = Convert.ToInt32(e.CellValue.ToString());
                            cellvalue = b;
                        }
                        b *= 255;
                        if (m_MaxValueInTable != 0)
                        {
                            b /= m_MaxValueInTable;
                        }
                        int red = 128;
                        int green = 128;
                        int blue = 128;
                        Color c = Color.White;
                        if (m_map_name == "TargetAFR" || m_map_name == "FeedbackAFR" || m_map_name == "FeedbackvsTargetAFR" || m_map_name == "IdleTargetAFR" || m_map_name == "IdleFeedbackAFR" || m_map_name == "IdleFeedbackvsTargetAFR" || m_OnlineMode)
                        {
                            b /= 2;
                            red = b;
                            if (red < 0) red = 0;
                            if (red > 255) red = 255;
                            if (b > 255) b = 255;
                            green = 255-red;
                            blue = 255 - red;
                            c = Color.FromArgb(red, green, blue);
                           // if (b == 0) c = Color.Transparent;

                        }
                        else if (!m_isRedWhite)
                        {
                            red = b;
                            if (red < 0) red = 0;
                            if (red > 255) red = 255;
                            if (b > 255) b = 255;
                            blue = 0;
                            green = 255 - red;
                            c = Color.FromArgb(red, green, blue);
                        }
                        else
                        {
                            if (b < 0) b = -b;
                            if (b > 255) b = 255;
                            c = Color.FromArgb(b, Color.Red);
                        }
                        if (!m_disablecolors)
                        {
                            SolidBrush sb = new SolidBrush(c);
                            e.Graphics.FillRectangle(sb, e.Bounds);
                        }
                        // draw indicator for changed by user
                        try
                        {
                            if (m_values_changed_highlight_user != null)
                            {
                                byte bchangeduser = Convert.ToByte(m_values_changed_highlight_user.GetValue((e.RowHandle * m_TableWidth) + e.Column.AbsoluteIndex));
                                if (bchangeduser > 0)
                                {
                                    // draw triangle
                                    Point[] pnts = new Point[4];
                                    pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y), 0);
                                    pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width - (e.Bounds.Height / 2), e.Bounds.Y), 1);
                                    pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y + (e.Bounds.Height / 2)), 2);
                                    pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y), 3);
                                    e.Graphics.FillPolygon(Brushes.Yellow, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                                }
                                
                            }
                            if(m_values_changed_highlight_ecu != null)
                            {
                                byte bchangedecu = Convert.ToByte(m_values_changed_highlight_ecu.GetValue((e.RowHandle * m_TableWidth) + e.Column.AbsoluteIndex));
                                if (bchangedecu > 0)
                                {
                                    // draw triangle
                                    Point[] pnts = new Point[4];
                                    pnts.SetValue(new Point(e.Bounds.X, e.Bounds.Y), 0);
                                    pnts.SetValue(new Point(e.Bounds.X + (e.Bounds.Height / 2), e.Bounds.Y), 1);
                                    pnts.SetValue(new Point(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height / 2)), 2);
                                    pnts.SetValue(new Point(e.Bounds.X, e.Bounds.Y), 3);
                                    e.Graphics.FillPolygon(Brushes.Orange, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                                }
                            }
                        }
                        catch /*(Exception changedUserE)*/
                        {
                            //Console.WriteLine("Failed to draw changed by user indicator: " + changedUserE.Message);
                        }

                        if (m_viewtype == Trionic5Tools.ViewType.Easy || m_viewtype == Trionic5Tools.ViewType.Easy3Bar || m_viewtype == Trionic5Tools.ViewType.Easy35Bar || m_viewtype == Trionic5Tools.ViewType.Easy4Bar || m_viewtype == Trionic5Tools.ViewType.Easy5Bar)
                        {
                            float dispvalue = 0;
                            dispvalue = (float)cellvalue;
                            if (correction_offset != 0 || correction_factor != 1)
                            {
                                dispvalue = (float)((float)cellvalue * (float)correction_factor) + (float)correction_offset;
                                if (m_viewtype != Trionic5Tools.ViewType.Hexadecimal)
                                //if (!m_isHexMode)
                                {
                                    if (m_map_name.StartsWith("Ign_map_0!") || m_map_name.StartsWith("Ign_map_4!"))
                                    {
                                        e.DisplayText = dispvalue.ToString("F1") + "\u00b0";
                                        /*if (dispvalue < 0)
                                        {
                                            Console.WriteLine("Negative value:  " + cellvalue.ToString());

                                        }*/
                                    }
                                    else if (m_map_name.StartsWith("Reg_kon_mat"))
                                    {
                                        e.DisplayText = dispvalue.ToString("F0") + @"%";
                                    }
                                    else if (m_map_name.StartsWith("FeedbackAFR") || m_map_name.StartsWith("FeedbackvsTargetAFR") || m_map_name.StartsWith("IdleFeedbackAFR") || m_map_name.StartsWith("IdleFeedbackvsTargetAFR"))
                                    {
                                        if (dispvalue == 0)
                                        {
                                            e.DisplayText = "";
                                        }
                                        else
                                        {
                                            e.DisplayText = dispvalue.ToString("F2");
                                        }
                                    }
                                    else
                                    {
                                        e.DisplayText = dispvalue.ToString("F2");
                                    }
                                }
                                else
                                {
                                    //e.DisplayText = dispvalue.ToString();
                                }
                            }
                            else if (m_map_name.StartsWith("Reg_kon_mat"))
                            {
                                e.DisplayText = dispvalue.ToString("F0") + @"%";
                            }
                        }

                        //  if mapname is Insp_mat or Fuel_knock_map indicate open/closed loop operation
                        // the map indicating where the ecu switches to open loop should be loaded into... 
                        // for Fuel_knock_map this is Open_loop_knock!
                        // for Insp_mat this is Open_loop!
                        //e.Column.AbsoluteIndex

                        bool lock_drawn = false;
                        if (m_map_name == "Ign_map_0!" || m_map_name == "Knock_count_map")
                        {
                            try
                            {
                                if (turbo_press_tab != null)
                                {
                                    int mapvalue = x_axisvalues[e.Column.AbsoluteIndex];
                                    int rpmvalue = y_axisvalues[e.RowHandle];
                                    if (turbo_press_tab.Length > 0)
                                    {
                                        int mapopenloop = (int)turbo_press_tab[(open_loop.Length - e.RowHandle) - 1];
                                        if (mapopenloop > mapvalue)
                                        {
                                            int pos = (e.Bounds.Width) - 12;
                                            int ypos = (e.Bounds.Height / 2) - 5;
                                            if (pos >= 0)
                                            {
                                                System.Drawing.Image cflag = (Image)global::Trionic5Controls.Properties.Resources.db_lock16_h;
                                                e.Graphics.DrawImage(cflag, e.Bounds.X + pos, e.Bounds.Y + ypos, 10, 10);
                                                lock_drawn = true;
                                            }
                                        }
                                    }
                                }
                                if (ignition_lock_map != null)
                                {
                                    int mapvalue = x_axisvalues[e.Column.AbsoluteIndex];
                                    int rpmvalue = y_axisvalues[e.RowHandle];
                                    if (ignition_lock_map.Length > 0)
                                    {
                                        int locked = (int)ignition_lock_map[(e.RowHandle * m_TableWidth) + e.Column.AbsoluteIndex];

                                        if (locked > 0 && !lock_drawn)
                                        {
                                            // draw lock icon
                                            int pos = (e.Bounds.Width) - 12;
                                            int ypos = (e.Bounds.Height / 2) - 5;
                                            if (pos >= 0)
                                            {
                                                System.Drawing.Image cflag = (Image)global::Trionic5Controls.Properties.Resources.db_lock16_h;
                                                e.Graphics.DrawImage(cflag, e.Bounds.X + pos, e.Bounds.Y + ypos, 10, 10);
                                                lock_drawn = true;
                                            }

                                        }
                                    }
                                }
                            }
                            catch (Exception E)
                            {
                                Console.WriteLine("Failed to mark cell as locked: " + E.Message);
                            }
                        }
                        if (m_map_name == "Insp_mat!" || m_map_name == "Inj_map_0!" || m_map_name == "TargetAFR" || m_map_name == "FeedbackAFR" || m_map_name == "FeedbackvsTargetAFR")
                        {
                            // show locked indicators from afr_lock_map
                            try
                            {
                                if (afr_lock_map != null)
                                {
                                    int mapvalue = x_axisvalues[e.Column.AbsoluteIndex];
                                    int rpmvalue = y_axisvalues[e.RowHandle];
                                    if (afr_lock_map.Length > 0)
                                    {
                                        int locked = (int)afr_lock_map[(e.RowHandle * m_TableWidth) + e.Column.AbsoluteIndex];

                                        if (locked > 0)
                                        {
                                            // draw lock icon
                                            int pos = (e.Bounds.Width) - 12;
                                            int ypos = (e.Bounds.Height / 2) - 5;
                                            if (pos >= 0)
                                            {
                                                System.Drawing.Image cflag = (Image)global::Trionic5Controls.Properties.Resources.db_lock16_h;
                                                e.Graphics.DrawImage(cflag, e.Bounds.X + pos, e.Bounds.Y + ypos, 10, 10);
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception E)
                            {
                                Console.WriteLine("Failed to mark cell as locked: " + E.Message);
                            }
                        }
                        if (m_map_name == "Idle_fuel_korr!" || m_map_name == "IdleTargetAFR" || m_map_name == "IdleFeedbackAFR" || m_map_name == "IdleFeedbackvsTargetAFR")
                        {
                            // show locked indicators from Idleafr_lock_map
                            try
                            {
                                if (idle_afr_lock_map != null)
                                {
                                    int mapvalue = x_axisvalues[e.Column.AbsoluteIndex];
                                    int rpmvalue = y_axisvalues[e.RowHandle];
                                    if (idle_afr_lock_map.Length > 0)
                                    {
                                        int locked = (int)idle_afr_lock_map[(e.RowHandle * m_TableWidth) + e.Column.AbsoluteIndex];

                                        if (locked > 0)
                                        {
                                            // draw lock icon
                                            int pos = (e.Bounds.Width) - 12;
                                            int ypos = (e.Bounds.Height / 2) - 5;
                                            if (pos >= 0)
                                            {
                                                System.Drawing.Image cflag = (Image)global::Trionic5Controls.Properties.Resources.db_lock16_h;
                                                e.Graphics.DrawImage(cflag, e.Bounds.X + pos, e.Bounds.Y + ypos, 10, 10);
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception E)
                            {
                                Console.WriteLine("Failed to mark cell as locked: " + E.Message);
                            }
                        }
                        if (m_map_name == "Insp_mat!" || m_map_name == "Inj_map_0!" || m_map_name == "Ign_map_0!" || m_map_name == "TargetAFR" || m_map_name == "FeedbackAFR" || m_map_name == "FeedbackvsTargetAFR" || m_map_name == "IdleTargetAFR" || m_map_name == "IdleFeedbackAFR" || m_map_name == "IdleFeedbackvsTargetAFR")
                        {
                            try
                            {
                                if (open_loop != null)
                                {
                                    int mapvalue = x_axisvalues[e.Column.AbsoluteIndex];
                                    int rpmvalue = y_axisvalues[e.RowHandle];
                                    if (open_loop.Length > 0)
                                    {
                                        int mapopenloop = (int)open_loop[(open_loop.Length - e.RowHandle) - 1];
                                        if (mapopenloop > mapvalue)
                                        {
                                            //e.Graphics.FillEllipse(Brushes.Black, e.Bounds.X, e.Bounds.Y, e.Bounds.X + 10, e.Bounds.Y+10);
                                            //e.Graphics.FillEllipse(Brushes.Yellow, e.Bounds.X+2, e.Bounds.Y+2, 4,4);
                                            Pen p = new Pen(Brushes.Black, 2);
                                            e.Graphics.DrawRectangle(p, e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width -2 , e.Bounds.Height -2);
                                            p.Dispose();
                                          //  DrawHighlight(e.Graphics, e.Bounds);
                                        }
                                    }
                                }
                                if (_knockadaptloadfrom != 0 || _knockadaptloadupto != 0 || _knockadaptrpmfrom != 0 || _knockadaptrpmupto != 0)
                                {
                                    /*
                                    int mapvalue = x_axisvalues[e.Column.AbsoluteIndex];
                                    int rpmvalue = y_axisvalues[e.RowHandle];
                                    if (rpmvalue >= _knockadaptrpmfrom && rpmvalue <= _knockadaptrpmupto && mapvalue >= _knockadaptloadfrom && mapvalue <= _knockadaptloadupto)
                                    {
                                        Pen p = new Pen(Brushes.Blue, 1);
                                        e.Graphics.DrawRectangle(p, e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 5, e.Bounds.Height - 5);
                                        p.Dispose();

                                    }
                                     */
                                    int mapvalue = x_axisvalues[e.Column.AbsoluteIndex];
                                    int rpmvalue = y_axisvalues[y_axisvalues.Length - e.RowHandle - 1];
                                    if (rpmvalue >= _knockadaptrpmfrom && rpmvalue <= _knockadaptrpmupto && mapvalue >= _knockadaptloadfrom && mapvalue <= _knockadaptloadupto)
                                    {
                                        Pen p = new Pen(Brushes.Blue, 1);
                                        e.Graphics.DrawRectangle(p, e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 5, e.Bounds.Height - 5);
                                        p.Dispose();

                                    }

                                }
                                if (_boostadaptrpmfrom != 0 || _boostadaptrpmupto != 0)
                                {
                                    /*if (e.Column.AbsoluteIndex == x_axisvalues.Length - 1)
                                    {
                                        int rpmvalue = y_axisvalues[y_axisvalues.Length - e.RowHandle - 1];
                                        if (rpmvalue >= _boostadaptrpmfrom && rpmvalue <= _boostadaptrpmupto)
                                        {
                                            Pen p = new Pen(Brushes.White, 1);
                                            e.Graphics.DrawRectangle(p, e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 5, e.Bounds.Height - 5);
                                            p.Dispose();
                                        }
                                    }*/
                                    if (e.Column.AbsoluteIndex == x_axisvalues.Length - 1)
                                    {
                                        int rpmvalue = y_axisvalues[y_axisvalues.Length - e.RowHandle - 1];
                                        if (rpmvalue >= _boostadaptrpmfrom && rpmvalue <= _boostadaptrpmupto)
                                        {
                                            Pen p = new Pen(Brushes.White, 1);
                                            e.Graphics.DrawRectangle(p, e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 5, e.Bounds.Height - 5);
                                            p.Dispose();
                                        }
                                    }

                                }
                                if (m_map_name.StartsWith("Feedback"))
                                {
                                    if (afr_counter != null)
                                    {
                                        // fetch correct counter
                                        int current_afrcounter = (int)afr_counter[(afr_counter.Length - ((e.RowHandle +1) * m_TableWidth)) + e.Column.AbsoluteIndex ];
                                        //current_afrcounter /= 10;
                                        if(current_afrcounter > 255) current_afrcounter = 255;
                                        if (current_afrcounter != 0)
                                        {
                                            Color cc = Color.FromArgb(255 - current_afrcounter, current_afrcounter, 0);

                                            Pen p = new Pen(cc, 1);
                                            e.Graphics.DrawRectangle(p, e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 5, e.Bounds.Height - 5);
                                            p.Dispose();
                                        }
                                        /*if (current_afrcounter < 100)
                                        {
                                            // one star
                                        }
                                        else if (current_afrcounter < 200)
                                        {
                                            // two stars
                                        }
                                        else if (current_afrcounter < 300)
                                        {
                                            // three stars
                                        }
                                        else if (current_afrcounter < 400)
                                        {
                                            // four stars
                                        }
                                        else
                                        {
                                            // five stars
                                        }*/

                                    }
                                }
                            }
                            catch (Exception E)
                            {
                                Console.WriteLine(E.Message);
                            }

                        }
                        else if (m_map_name == "Fuel_knock_mat!")
                        {
                            try
                            {
                                if (open_loop_knock != null)
                                {
                                    if (open_loop_knock.Length > 0)
                                    {
                                        int mapvalue = x_axisvalues[e.Column.AbsoluteIndex];
                                        int rpmvalue = y_axisvalues[e.RowHandle];
                                        int mapopenloop = (int)open_loop_knock[(open_loop_knock.Length - e.RowHandle) - 1];
                                        if (mapopenloop > mapvalue)
                                        {
                                            //e.Graphics.FillEllipse(Brushes.Black, e.Bounds.X, e.Bounds.Y, e.Bounds.X + 10, e.Bounds.Y+10);
                                            //e.Graphics.FillEllipse(Brushes.Yellow, e.Bounds.X+2, e.Bounds.Y+2, 4,4);
                                            Pen p = new Pen(Brushes.Black, 2);
                                            e.Graphics.DrawRectangle(p, e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2);
                                            p.Dispose();
                                            //  DrawHighlight(e.Graphics, e.Bounds);
                                        }
                                    }
                                }
                            }
                            catch (Exception E)
                            {
                                Console.WriteLine(E.Message);
                            }

                        }
                        /*else if (m_map_name == "Ign_map_0!" ||m_map_name == "Ign_map_2!" ||m_map_name == "Ign_map_4!" )
                        {
                            try
                            {
                                if (open_loop != null)
                                {
                                    if (open_loop.Length > 0)
                                    {
                                        int mapvalue = x_axisvalues[e.Column.AbsoluteIndex];
                                        int rpmvalue = y_axisvalues[e.RowHandle];
                                        int mapopenloop = (int)open_loop[(open_loop.Length - e.RowHandle) - 1];
                                        if (mapopenloop > mapvalue)
                                        {
                                            //e.Graphics.FillEllipse(Brushes.Black, e.Bounds.X, e.Bounds.Y, e.Bounds.X + 10, e.Bounds.Y+10);
                                            //e.Graphics.FillEllipse(Brushes.Yellow, e.Bounds.X+2, e.Bounds.Y+2, 4,4);
                                            Pen p = new Pen(Brushes.Black, 2);
                                            e.Graphics.DrawRectangle(p, e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2);
                                            p.Dispose();
                                            //  DrawHighlight(e.Graphics, e.Bounds);
                                        }
                                    }
                                }
                            }
                            catch (Exception E)
                            {
                                Console.WriteLine(E.Message);
                            }

                        }
                        else if (m_map_name == "Tryck_mat!" || m_map_name == "Tryck_mat_a!")
                        {
                            try
                            {
                                if (open_loop != null)
                                {
                                    if (open_loop.Length > 0)
                                    {
                                        int mapvalue = Convert.ToInt32(e.CellValue);
                                        int rpmvalue = y_axisvalues[e.RowHandle];
                                        int mapopenloop = (int)open_loop[(open_loop.Length - e.RowHandle) - 1];
                                        if (mapopenloop > mapvalue)
                                        {
                                            //e.Graphics.FillEllipse(Brushes.Black, e.Bounds.X, e.Bounds.Y, e.Bounds.X + 10, e.Bounds.Y+10);
                                            //e.Graphics.FillEllipse(Brushes.Yellow, e.Bounds.X+2, e.Bounds.Y+2, 4,4);
                                            Pen p = new Pen(Brushes.Black, 2);
                                            e.Graphics.DrawRectangle(p, e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2);
                                            p.Dispose();
                                            //  DrawHighlight(e.Graphics, e.Bounds);
                                        }
                                    }
                                }
                            }
                            catch (Exception E)
                            {
                                Console.WriteLine(E.Message);
                            }

                        }*/

                    }
                }

                // draw realtime highlight!
                if (m_selectedrowhandle >= 0 && m_selectedcolumnindex >= 0)
                {
                    if (e.RowHandle == m_selectedrowhandle && e.Column.AbsoluteIndex == m_selectedcolumnindex)
                    {
                        SolidBrush sbsb = new SolidBrush(Color.Yellow);
                        e.Graphics.FillRectangle(sbsb, e.Bounds);
                    }
                }

            }
            catch (Exception E)
            {
                Console.WriteLine(E.Message);
            }
        }
示例#7
0
        private void SetSelectedColor(UniColor?selc = null)
        {
            UniColor clr;

            if (selc != null)
            {
                clr           = (UniColor)selc;
                SelectedColor = Color.FromArgb(clr.A, clr.R, clr.G, clr.B);

                return;
            }
            else if (SelectedColor == null)
            {
                SelectedColorName    = null;
                Point.Visibility     = Surround.Visibility = Visibility.Hidden;
                HuePicker.Visibility = Visibility.Hidden;
                return;
            }

            clr = ((Color)SelectedColor).GetUniColor();

            var nc = NamedColor.FindColor(clr, NameResolution == ColorNameResolution.Closest);

            if (nc != null)
            {
                SelectedColorName = nc.Name;
            }
            else
            {
                SelectedColorName = clr.ToString(UniColorFormatOptions.HexRgbWebFormat);
            }

            if (cpRender == null)
            {
                return;
            }

            HSVDATA  hsv1 = ColorToHSV(clr);
            HSVDATA  hsv2;
            HSVDATA  hsv3;
            HSVDATA? hsv4 = null;
            HSVDATA? hsv5 = null;
            UniColor uc;

            ColorPickerElement cel = new ColorPickerElement();

            foreach (var c in cpRender.Elements)
            {
                uc = c.Color;

                hsv2 = ColorToHSV(uc);
                hsv3 = (hsv1 - hsv2).Abs();

                if (hsv4 == null)
                {
                    hsv4 = hsv3;
                }
                else if (hsv3 < hsv4)
                {
                    hsv5 = hsv2;
                    hsv4 = hsv3;
                    cel  = c;
                }

                if (selc == uc)
                {
                    cel = c;
                    break;
                }
            }

            if (Mode == ColorPickerMode.HueWheel && !double.IsNaN(ActualWidth) && !double.IsNaN(ActualHeight) && ActualWidth != -1 && ActualHeight != -1)
            {
                if (hsv5 is HSVDATA hsv)
                {
                    Point.Visibility     = Surround.Visibility = Visibility.Hidden;
                    HuePicker.Visibility = Visibility.Visible;
                    int hp = HuePointerSize;

                    PolarCoordinates pc = new PolarCoordinates();

                    double arc = hsv.Hue - HueOffset;
                    if (arc < 0)
                    {
                        arc += 360;
                    }

                    int rad;
                    int h = (int)ActualHeight, w = (int)ActualWidth;

                    if (h < w)
                    {
                        rad = h / 2;
                        w   = h;
                    }
                    else
                    {
                        rad = w / 2;
                        h   = w;
                    }

                    pc.Arc    = arc;
                    pc.Radius = rad;

                    var lc = pc.ToScreenCoordinates(new Rect(0, 0, w, h));

                    if (lc.X < (w / 2))
                    {
                        lc.X -= hp;
                    }

                    if (lc.Y < (h / 2))
                    {
                        lc.Y -= hp;
                    }

                    HuePicker.SetValue(Canvas.LeftProperty, lc.X);
                    HuePicker.SetValue(Canvas.TopProperty, lc.Y);

                    HueSize.ScaleX = (HuePointerSize / 5);
                    HueSize.ScaleY = (HuePointerSize / 5);

                    HueAngle.Angle = pc.Arc;
                }
            }
            else
            {
                Point.Visibility     = Surround.Visibility = Visibility.Visible;
                HuePicker.Visibility = Visibility.Hidden;

                Point.SetValue(Canvas.LeftProperty, (double)cel.Center.X);
                Point.SetValue(Canvas.TopProperty, (double)cel.Center.Y);

                Surround.SetValue(Canvas.LeftProperty, (double)cel.Center.X - 8);
                Surround.SetValue(Canvas.TopProperty, (double)cel.Center.Y - 8);

                Surround.Stroke = Point.Stroke = new SolidColorBrush((Color)SelectedColor);
                selectedElement = cel;
            }
        }
        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            try
            {
                if (e.CellValue != null)
                {
                    if (e.CellValue != DBNull.Value)
                    {
                        int b = 0;
                        int cellvalue = 0;
                        //if (m_isHexMode)
                        b = Convert.ToInt32(e.CellValue.ToString());
                        cellvalue = b;
                        b *= 255;
                        if (m_MaxValueInTable != 0)
                        {
                            b /= m_MaxValueInTable;
                        }
                        int red = 128;
                        int green = 128;
                        int blue = 128;
                        Color c = Color.White;
                        red = b;
                        if (red < 0) red = 0;
                        if (red > 255) red = 255;
                        if (b > 255) b = 255;
                        blue = 0;
                        green = 255 - red;
                        c = Color.FromArgb(red, green, blue);
                        SolidBrush sb = new SolidBrush(c);
                        e.Graphics.FillRectangle(sb, e.Bounds);

                        // check limiter type
                        //limitermap
                        int row = rows - (e.RowHandle + 1);
                        limitType curLimit = (limitType)limitermap.GetValue((row * columns) + e.Column.AbsoluteIndex);
                        Point[] pnts = new Point[4];
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y), 0);
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width - (e.Bounds.Height / 2), e.Bounds.Y), 1);
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y + (e.Bounds.Height / 2)), 2);
                        pnts.SetValue(new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y), 3);
                        if (curLimit == limitType.AirmassLimiter)
                        {
                            e.Graphics.FillPolygon(Brushes.Blue, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TorqueLimiterEngine)
                        {
                            e.Graphics.FillPolygon(Brushes.Yellow, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TurboSpeedLimiter)
                        {
                            e.Graphics.FillPolygon(Brushes.Black, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.TorqueLimiterGear)
                        {
                            e.Graphics.FillPolygon(Brushes.SaddleBrown, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        else if (curLimit == limitType.FuelCutLimiter)
                        {
                            e.Graphics.FillPolygon(Brushes.DarkGray, pnts, System.Drawing.Drawing2D.FillMode.Winding);
                        }
                        if (comboBoxEdit2.SelectedIndex == 1)
                        {
                            // convert airmass to torque
                            if (_ECUType.Contains("EDC16"))
                            {
                                int rpm = Convert.ToInt32(y_axisvalues.GetValue(e.Column.AbsoluteIndex));
                                int torque = Convert.ToInt32(e.CellValue);
                                torque /= 10;
                                e.DisplayText = torque.ToString();
                            }
                            else
                            {
                                int rpm = Convert.ToInt32(y_axisvalues.GetValue(e.Column.AbsoluteIndex));
                                int torque = Tools.Instance.IQToTorque(Convert.ToInt32(e.CellValue), rpm, m_numberCylinders);
                                if (checkEdit6.Checked)
                                {
                                    torque = Tools.Instance.IQToTorque(Convert.ToInt32(e.CellValue), rpm, m_numberCylinders);// AirmassToTorqueLbft(Convert.ToInt32(e.CellValue), rpm);
                                }
                                torque /= 100;
                                e.DisplayText = torque.ToString();
                            }
                        }
                        else if (comboBoxEdit2.SelectedIndex == 2)
                        {
                            if (_ECUType.Contains("EDC16"))
                            {
                                int rpm = Convert.ToInt32(y_axisvalues.GetValue(e.Column.AbsoluteIndex));
                                int torque = Convert.ToInt32(e.CellValue);
                                torque /= 10;
                                double temptorque = torque * Tools.Instance.GetCorrectionFactorForRpm(rpm, m_numberCylinders);
                                torque = Convert.ToInt32(temptorque);
                                int horsepower = Tools.Instance.TorqueToPower(torque, rpm);
                                if (checkEdit5.Checked)
                                {
                                    horsepower = Tools.Instance.TorqueToPowerkW(torque, rpm);
                                }
                                e.DisplayText = horsepower.ToString();
                            }
                            else
                            {
                                //convert airmass to horsepower
                                int rpm = Convert.ToInt32(y_axisvalues.GetValue(e.Column.AbsoluteIndex));
                                int torque = Tools.Instance.IQToTorque(Convert.ToInt32(e.CellValue), rpm, m_numberCylinders);
                                int horsepower = Tools.Instance.TorqueToPower(torque, rpm);
                                if (checkEdit5.Checked)
                                {
                                    horsepower = Tools.Instance.TorqueToPowerkW(torque, rpm);
                                }
                                horsepower /= 100;
                                e.DisplayText = horsepower.ToString();
                            }
                        }
                        else
                        {
                            if (_ECUType.Contains("EDC16"))
                            {
                                // should display IQ in stead of torque
                                int rpm = Convert.ToInt32(y_axisvalues.GetValue(e.Column.AbsoluteIndex));
                                int torque = Convert.ToInt32(e.CellValue);
                                torque /= 10;
                                e.DisplayText = Tools.Instance.TorqueToIQ(torque, rpm, m_numberCylinders).ToString();
                            }
                            else
                            {
                                int airmass = Convert.ToInt32(e.CellValue);
                                airmass /= 100;
                                e.DisplayText = airmass.ToString();
                            }
                        }
                    }
                }
            }
            catch (Exception E)
            {
                Console.WriteLine(E.Message);
            }
        }