Esempio n. 1
0
 public GraphicsText(double x, double y, string text, Brush foreground, Brush background, GraphicsElement element, double fontSize)
 {
     X          = x;
     Y          = y;
     Text       = text;
     Foreground = foreground;
     Background = background;
     Element    = element;
     FontSize   = fontSize;
 }
        void RedrawLoadFlow()
        {
            if (!loadFlowChanged || topology == null)
            {
                return;
            }

            loadFlowChanged = false;
            List <GraphicsText> loadFlows = new List <GraphicsText>();

            for (int i = 0; i < elements.Count; ++i)
            {
                GraphicsElement element = elements[i];

                if (element.IO == null)
                {
                    continue;
                }

                LoadFlowResult lfResult = topology.GetLoadFlow(element.IO.GID);

                if (lfResult == null)
                {
                    continue;
                }

                switch (ModelCodeHelper.GetTypeFromGID(element.IO.GID))
                {
                case DMSType.ConnectivityNode:
                {
                    double ur = lfResult.Get(LoadFlowResultType.UR);
                    double ui = lfResult.Get(LoadFlowResultType.UI);

                    if (double.IsNaN(ur) || double.IsNaN(ui))
                    {
                        break;
                    }

                    GraphicsText gtu = new GraphicsText(element.X + loadFlowXOffset, 0, GetLoadFlowItemText(ur, ui, "V"), Brushes.Black, Brushes.Transparent, element, loadFlowFontSize);
                    gtu.Y = element.Y - gtu.CalculateSize().Height / 2;
                    loadFlows.Add(gtu);
                }
                break;

                case DMSType.ACLineSegment:
                {
                    double ir = lfResult.Get(LoadFlowResultType.IR);
                    double ii = lfResult.Get(LoadFlowResultType.II);
                    double sr = lfResult.Get(LoadFlowResultType.SR);
                    double si = lfResult.Get(LoadFlowResultType.SI);

                    if (double.IsNaN(ir) || double.IsNaN(ii) || double.IsNaN(sr) || double.IsNaN(si))
                    {
                        break;
                    }

                    bool         abnormalCurrent = ComplexLength(ir, ii) > ((ACLineSegment)element.IO).RatedCurrent;
                    GraphicsText gti             = new GraphicsText(element.X + loadFlowXOffset, 0, GetLoadFlowItemText(ir, ii, "A"), abnormalCurrent ? Brushes.White : Brushes.Black, abnormalCurrent ? Brushes.DarkRed : Brushes.Transparent, element, loadFlowFontSize);
                    GraphicsText gts             = new GraphicsText(element.X + loadFlowXOffset, 0, GetLoadFlowItemText(sr, si, "VA"), Brushes.Black, Brushes.Transparent, element, loadFlowFontSize);
                    Size         gtiSize         = gti.CalculateSize();
                    Size         gtsSize         = gts.CalculateSize();

                    gti.Y = element.Y - (gtiSize.Height + gtsSize.Height) / 2;
                    gts.Y = gti.Y + gtiSize.Height;

                    loadFlows.Add(gti);
                    loadFlows.Add(gts);
                }
                break;

                case DMSType.EnergyConsumer:
                {
                    double sr = lfResult.Get(LoadFlowResultType.SR);
                    double si = lfResult.Get(LoadFlowResultType.SI);

                    if (double.IsNaN(sr) || double.IsNaN(si))
                    {
                        break;
                    }

                    GraphicsText gts = new GraphicsText(0, element.Y + loadFlowYOffset, GetLoadFlowItemText(sr, si, "VA"), Brushes.Black, Brushes.Transparent, element, loadFlowFontSize);
                    gts.X = element.X - gts.CalculateSize().Width / 2;
                    loadFlows.Add(gts);
                }
                break;
                }
            }

            this.loadFlows = loadFlows;
        }