private int FindBetterPointForCurveTitleDrawing(TrainCurveData c, int startIndex, int endIndex, Rectangle rc)
        {
            Point point = this.PointData2Point(c.Points[endIndex], rc);

            for (int i = startIndex; (i < c.Points.Count) && (i <= endIndex); i++)
            {
                if (Math.Abs(SilverlightHelper.GetRotationAngle(this.PointData2Point(c.Points[i], rc), point)) < 30.0)
                {
                    return(i);
                }
            }
            return(startIndex);
        }
        private bool GetGoodPointsForTitle(TrainCurveData c, int startIndex, Rectangle rc, double widthRequires, out int i1, out int i2, out int nextStartIndex, out bool resetNextStartIndex)
        {
            i1                  = startIndex;
            i2                  = startIndex;
            nextStartIndex      = startIndex;
            resetNextStartIndex = false;
            Point  point = this.PointData2Point(c.Points[startIndex], rc);
            double num   = 0.0;

            for (int i = startIndex + 1; i < (c.Points.Count - 1); i++)
            {
                PointData data   = c.Points[i];
                PointData data2  = c.Points[i + 1];
                Point     point2 = this.PointData2Point(data, rc);
                Point     point3 = this.PointData2Point(data2, rc);
                TimeSpan  span   = (TimeSpan)(data.DateTime - data2.DateTime);
                if (this.IsGap((double)(data.Position - data2.Position), span.TotalMinutes))
                {
                    nextStartIndex      = i + 1;
                    resetNextStartIndex = true;
                    return(false);
                }
                if (i == (startIndex + 1))
                {
                    num = point2.get_X() - point.get_X();
                }
                else
                {
                    double num3 = point3.get_X() - point2.get_X();
                    if ((num * num3) < 0.0)
                    {
                        nextStartIndex      = i + 1;
                        resetNextStartIndex = true;
                        return(false);
                    }
                }
                if (Math.Abs((double)(point.get_X() - point2.get_X())) >= widthRequires)
                {
                    i2 = i;
                    i1 = this.FindBetterPointForCurveTitleDrawing(c, startIndex, i, rc);
                    return(true);
                }
            }
            return(false);
        }
        private void DrawCurves(Rectangle rc, bool full)
        {
            SilverlightHelper.Debug("DrawCurves started");
            List <TrainCurveData> list  = new List <TrainCurveData>();
            List <TrainCurveData> list2 = new List <TrainCurveData>();

            foreach (CurveData data in this.m_tgd.Curves)
            {
                TrainCurveData item = new TrainCurveData {
                    CaptionHasDrawn = false,
                    Caption         = data.Caption,
                    Name            = data.Name,
                    Points          = data.Points,
                    Regular         = data.Regular
                };
                if (item.Regular)
                {
                    list.Add(item);
                }
                else
                {
                    list2.Add(item);
                }
            }
            if (full)
            {
                SilverlightHelper.Debug("Regular curves draw started");
                if (list.Count > 0)
                {
                    this.m_regularCurves = list;
                }
                List <Line> rectangles = new List <Line>();
                foreach (TrainCurveData data2 in this.m_regularCurves)
                {
                    this.DrawCurve(data2, rc, rectangles, 0);
                }
                SilverlightHelper.Debug("Regular curves draw finished");
            }
            SilverlightHelper.Debug("Realtime curves draw started");
            Dictionary <string, int> dictionary = new Dictionary <string, int>();

            foreach (TrainCurveData data2 in list2)
            {
                if (!this.m_name2RealtimeCurve.ContainsKey(data2.Name))
                {
                    this.m_name2RealtimeCurve[data2.Name] = new TrainCurveData();
                }
                this.m_name2RealtimeCurve[data2.Name].Caption = data2.Caption;
                this.m_name2RealtimeCurve[data2.Name].Name    = data2.Name;
                this.m_name2RealtimeCurve[data2.Name].Regular = data2.Regular;
                dictionary[data2.Name] = (this.m_name2RealtimeCurve[data2.Name].Points.Count > 0) ? (this.m_name2RealtimeCurve[data2.Name].Points.Count - 1) : 0;
                this.m_name2RealtimeCurve[data2.Name].Points.AddRange(data2.Points);
            }
            foreach (string str in dictionary.Keys)
            {
                int startIndex = dictionary[str];
                this.DrawCurve(this.m_name2RealtimeCurve[str], rc, null, startIndex);
            }
            SilverlightHelper.Debug("Realtime curves draw finished");
            SilverlightHelper.Debug("DrawCurves finished");
        }
 private void DrawCurve(TrainCurveData c, Rectangle rc, List <Line> rectangles, int startIndex)
 {
     if ((c != null) && (c.Points != null))
     {
         PointData data;
         PointData data2;
         int       num           = 0;
         int       num2          = -1;
         Line      item          = new Line();
         Color     color         = Colors.get_Black();
         double    widthRequires = 0.0;
         if (c.Points.Count > 0)
         {
             widthRequires = this.DrawCurveTitle(rc, c.Points[0], c.Points[0], c.Caption, false);
         }
         for (int i = startIndex; i < (c.Points.Count - 1); i++)
         {
             data  = c.Points[i];
             data2 = c.Points[i + 1];
             if (!c.Regular)
             {
                 TimeSpan span = (TimeSpan)(data.DateTime - data2.DateTime);
                 if (this.IsGap((double)(data.Position - data2.Position), span.TotalMinutes))
                 {
                     c.CaptionHasDrawn   = false;
                     c.CaptionStartIndex = i + 1;
                     continue;
                 }
             }
             color = SilverlightHelper.ConvertToColor(data2.Color);
             Line line2 = new Line();
             line2.set_X1(this.Position2PointX(data.Position, rc));
             line2.set_Y1(this.DateTime2PointY(data.DateTime, rc));
             line2.set_X2(this.Position2PointX(data2.Position, rc));
             line2.set_Y2(this.DateTime2PointY(data2.DateTime, rc));
             line2.set_Width(1251.0);
             line2.set_Height(this.CanvasRoot_ActualHeight);
             line2.set_StrokeThickness(2.0);
             line2.set_Stroke(new SolidColorBrush(color));
             this.CanvasRoot.get_Children().Add(line2);
             if (c.Regular && (c.Caption.Length > 0))
             {
                 if (!this.HasInsersection(rectangles, line2))
                 {
                     int num5 = data2.Position - data.Position;
                     if (num5 > num)
                     {
                         num  = num5;
                         num2 = i;
                         item = this.LineClone(line2);
                     }
                 }
             }
             else if (!c.CaptionHasDrawn)
             {
                 int  num6;
                 int  num7;
                 int  num8;
                 bool flag;
                 if (this.GetGoodPointsForTitle(c, c.CaptionStartIndex, rc, widthRequires, out num6, out num7, out num8, out flag))
                 {
                     c.CaptionHasDrawn = true;
                     this.DrawCurveTitle(rc, c.Points[num6], c.Points[num7], c.Caption, true);
                 }
                 else if (flag)
                 {
                     c.CaptionStartIndex = num8;
                 }
             }
         }
         if ((c.Regular && (c.Caption.Length > 0)) && (num2 != -1))
         {
             data  = c.Points[num2];
             data2 = c.Points[num2 + 1];
             color = SilverlightHelper.ConvertToColor(data2.Color);
             if (rectangles != null)
             {
                 rectangles.Add(item);
             }
             Point point  = new Point();
             Point point2 = new Point();
             point.set_X(this.Position2PointX(data.Position, rc));
             point.set_Y(this.DateTime2PointY(data.DateTime, rc));
             point2.set_X(this.Position2PointX(data2.Position, rc));
             point2.set_Y(this.DateTime2PointY(data2.DateTime, rc));
             double    rotationAngle = SilverlightHelper.GetRotationAngle(point, point2);
             double    num10         = point2.get_X() - point.get_X();
             TextBlock block         = new TextBlock();
             block.SetValue(Canvas.TopProperty, point.get_Y() + 5.0);
             block.SetValue(Canvas.LeftProperty, point.get_X());
             block.SetValue(FrameworkElement.WidthProperty, num10);
             block.SetValue(FrameworkElement.HeightProperty, 50.0);
             block.set_Width(num10);
             block.set_Text(c.Caption);
             block.set_FontSize(17.0);
             block.set_FontFamily(new FontFamily("Arial"));
             block.set_Foreground(new SolidColorBrush(color));
             block.set_FontStyle(FontStyles.get_Normal());
             block.set_FontWeight(FontWeights.get_Bold());
             RotateTransform transform = new RotateTransform();
             transform.set_Angle(-rotationAngle);
             block.set_RenderTransform(transform);
             block.set_TextAlignment(0);
             this.CanvasRoot.get_Children().Add(block);
         }
     }
 }
 private bool GetGoodPointsForTitle(TrainCurveData c, int startIndex, Rectangle rc, double widthRequires, out int i1, out int i2, out int nextStartIndex, out bool resetNextStartIndex)
 {
     i1 = startIndex;
     i2 = startIndex;
     nextStartIndex = startIndex;
     resetNextStartIndex = false;
     Point point = this.PointData2Point(c.Points[startIndex], rc);
     double num = 0.0;
     for (int i = startIndex + 1; i < (c.Points.Count - 1); i++)
     {
         PointData data = c.Points[i];
         PointData data2 = c.Points[i + 1];
         Point point2 = this.PointData2Point(data, rc);
         Point point3 = this.PointData2Point(data2, rc);
         TimeSpan span = (TimeSpan) (data.DateTime - data2.DateTime);
         if (this.IsGap((double) (data.Position - data2.Position), span.TotalMinutes))
         {
             nextStartIndex = i + 1;
             resetNextStartIndex = true;
             return false;
         }
         if (i == (startIndex + 1))
         {
             num = point2.get_X() - point.get_X();
         }
         else
         {
             double num3 = point3.get_X() - point2.get_X();
             if ((num * num3) < 0.0)
             {
                 nextStartIndex = i + 1;
                 resetNextStartIndex = true;
                 return false;
             }
         }
         if (Math.Abs((double) (point.get_X() - point2.get_X())) >= widthRequires)
         {
             i2 = i;
             i1 = this.FindBetterPointForCurveTitleDrawing(c, startIndex, i, rc);
             return true;
         }
     }
     return false;
 }
 private int FindBetterPointForCurveTitleDrawing(TrainCurveData c, int startIndex, int endIndex, Rectangle rc)
 {
     Point point = this.PointData2Point(c.Points[endIndex], rc);
     for (int i = startIndex; (i < c.Points.Count) && (i <= endIndex); i++)
     {
         if (Math.Abs(_SilverlightHelper.GetRotationAngle(this.PointData2Point(c.Points[i], rc), point)) < 30.0)
         {
             return i;
         }
     }
     return startIndex;
 }
 private void DrawCurves(Rectangle rc, bool full)
 {
     _SilverlightHelper.Debug("DrawCurves started");
     List<TrainCurveData> list = new List<TrainCurveData>();
     List<TrainCurveData> list2 = new List<TrainCurveData>();
     foreach (CurveData data in this.m_tgd.Curves)
     {
         TrainCurveData item = new TrainCurveData {
             CaptionHasDrawn = false,
             Caption = data.Caption,
             Name = data.Name,
             Points = data.Points,
             Regular = data.Regular
         };
         if (item.Regular)
         {
             list.Add(item);
         }
         else
         {
             list2.Add(item);
         }
     }
     if (full)
     {
         _SilverlightHelper.Debug("Regular curves draw started");
         if (list.Count > 0)
         {
             this.m_regularCurves = list;
         }
         List<Line> rectangles = new List<Line>();
         foreach (TrainCurveData data2 in this.m_regularCurves)
         {
             this.DrawCurve(data2, rc, rectangles, 0);
         }
         _SilverlightHelper.Debug("Regular curves draw finished");
     }
     _SilverlightHelper.Debug("Realtime curves draw started");
     Dictionary<string, int> dictionary = new Dictionary<string, int>();
     foreach (TrainCurveData data2 in list2)
     {
         if (!this.m_name2RealtimeCurve.ContainsKey(data2.Name))
         {
             this.m_name2RealtimeCurve[data2.Name] = new TrainCurveData();
         }
         this.m_name2RealtimeCurve[data2.Name].Caption = data2.Caption;
         this.m_name2RealtimeCurve[data2.Name].Name = data2.Name;
         this.m_name2RealtimeCurve[data2.Name].Regular = data2.Regular;
         dictionary[data2.Name] = (this.m_name2RealtimeCurve[data2.Name].Points.Count > 0) ? (this.m_name2RealtimeCurve[data2.Name].Points.Count - 1) : 0;
         this.m_name2RealtimeCurve[data2.Name].Points.AddRange(data2.Points);
     }
     foreach (string str in dictionary.Keys)
     {
         int startIndex = dictionary[str];
         this.DrawCurve(this.m_name2RealtimeCurve[str], rc, null, startIndex);
     }
     _SilverlightHelper.Debug("Realtime curves draw finished");
     _SilverlightHelper.Debug("DrawCurves finished");
 }
 private void DrawCurve(TrainCurveData c, Rectangle rc, List<Line> rectangles, int startIndex)
 {
     if ((c != null) && (c.Points != null))
     {
         PointData data;
         PointData data2;
         int num = 0;
         int num2 = -1;
         Line item = new Line();
         Color color = Colors.get_Black();
         double widthRequires = 0.0;
         if (c.Points.Count > 0)
         {
             widthRequires = this.DrawCurveTitle(rc, c.Points[0], c.Points[0], c.Caption, false);
         }
         for (int i = startIndex; i < (c.Points.Count - 1); i++)
         {
             data = c.Points[i];
             data2 = c.Points[i + 1];
             if (!c.Regular)
             {
                 TimeSpan span = (TimeSpan) (data.DateTime - data2.DateTime);
                 if (this.IsGap((double) (data.Position - data2.Position), span.TotalMinutes))
                 {
                     c.CaptionHasDrawn = false;
                     c.CaptionStartIndex = i + 1;
                     continue;
                 }
             }
             color = _SilverlightHelper.ConvertToColor(data2.Color);
             Line line2 = new Line();
             line2.set_X1(this.Position2PointX(data.Position, rc));
             line2.set_Y1(this.DateTime2PointY(data.DateTime, rc));
             line2.set_X2(this.Position2PointX(data2.Position, rc));
             line2.set_Y2(this.DateTime2PointY(data2.DateTime, rc));
             line2.set_Width(1251.0);
             line2.set_Height(this.CanvasRoot_ActualHeight);
             line2.set_StrokeThickness(2.0);
             line2.set_Stroke(new SolidColorBrush(color));
             this.CanvasRoot.get_Children().Add(line2);
             if (c.Regular && (c.Caption.Length > 0))
             {
                 if (!this.HasInsersection(rectangles, line2))
                 {
                     int num5 = data2.Position - data.Position;
                     if (num5 > num)
                     {
                         num = num5;
                         num2 = i;
                         item = this.LineClone(line2);
                     }
                 }
             }
             else if (!c.CaptionHasDrawn)
             {
                 int num6;
                 int num7;
                 int num8;
                 bool flag;
                 if (this.GetGoodPointsForTitle(c, c.CaptionStartIndex, rc, widthRequires, out num6, out num7, out num8, out flag))
                 {
                     c.CaptionHasDrawn = true;
                     this.DrawCurveTitle(rc, c.Points[num6], c.Points[num7], c.Caption, true);
                 }
                 else if (flag)
                 {
                     c.CaptionStartIndex = num8;
                 }
             }
         }
         if ((c.Regular && (c.Caption.Length > 0)) && (num2 != -1))
         {
             data = c.Points[num2];
             data2 = c.Points[num2 + 1];
             color = _SilverlightHelper.ConvertToColor(data2.Color);
             if (rectangles != null)
             {
                 rectangles.Add(item);
             }
             Point point = new Point();
             Point point2 = new Point();
             point.set_X(this.Position2PointX(data.Position, rc));
             point.set_Y(this.DateTime2PointY(data.DateTime, rc));
             point2.set_X(this.Position2PointX(data2.Position, rc));
             point2.set_Y(this.DateTime2PointY(data2.DateTime, rc));
             double rotationAngle = _SilverlightHelper.GetRotationAngle(point, point2);
             double num10 = point2.get_X() - point.get_X();
             TextBlock block = new TextBlock();
             block.SetValue(Canvas.TopProperty, point.get_Y() + 5.0);
             block.SetValue(Canvas.LeftProperty, point.get_X());
             block.SetValue(FrameworkElement.WidthProperty, num10);
             block.SetValue(FrameworkElement.HeightProperty, 50.0);
             block.set_Width(num10);
             block.set_Text(c.Caption);
             block.set_FontSize(17.0);
             block.set_FontFamily(new FontFamily("Arial"));
             block.set_Foreground(new SolidColorBrush(color));
             block.set_FontStyle(FontStyles.get_Normal());
             block.set_FontWeight(FontWeights.get_Bold());
             RotateTransform transform = new RotateTransform();
             transform.set_Angle(-rotationAngle);
             block.set_RenderTransform(transform);
             block.set_TextAlignment(0);
             this.CanvasRoot.get_Children().Add(block);
         }
     }
 }