Exemple #1
0
        private static void Update1DFromMG(
            GraphMicrogridLink link,
            Microgrid microgrid,
            GraphCanvas canvas)
        {
            int   tCount = microgrid.Input.tCount;
            float tSize  = microgrid.Input.tIncrementSize;

            if (MGMisc.accessorLists.ContainsKey(link.mvar))
            {
                var values = MGMisc.accessorLists[link.mvar]
                             .Get(microgrid);

                if (link.graphs.Count > 1)
                {
                    for (int i = link.graphs.Count - 1; i > 0; i--)
                    {
                        canvas.view.RemoveGraph(link.graphs[i]);
                        link.graphs.RemoveAt(i);
                    }

                    UpdateGraph(link, microgrid, values, 0);
                }
                else if (link.graphs.Count == 1)
                {
                    UpdateGraph(link, microgrid, values, 0);
                }
                else
                {
                    AddGraph(link, canvas, values, tCount, tSize);
                }
            }
        }
Exemple #2
0
 public void RemoveLink(GraphMicrogridLink link)
 {
     foreach (Graph graph in link.graphs)
     {
         graphCanvas.view.graphs.Remove(graph);
     }
     linksMutable.Remove(link);
 }
Exemple #3
0
        public void Setup()
        {
            RemoveAllLinks();
            LoadVarsFromMG(this, null);

            foreach (MicrogridVarAndIndex d in loadOnSetup)
            {
                var link = GraphMicrogridLink.Make(d.mvar, microgrid, d.index);
                AddLink(link);
            }
        }
Exemple #4
0
        private static void AddGraph(
            GraphMicrogridLink link,
            GraphCanvas canvas,
            IList <float> values,
            int tCount,
            float tSize)
        {
            var coords = ValuesToTimeAndValues(values, tCount, tSize);

            AddGraph(link, canvas, coords);
        }
Exemple #5
0
        private static void UpdateGraph(
            GraphMicrogridLink link,
            Microgrid microgrid,
            IList <float> values,
            int index)
        {
            var coords = ValuesToTimeAndValues(values,
                                               microgrid.Input.tCount,
                                               microgrid.Input.tIncrementSize);

            UpdateLinkExistingGraph(link, link.graphs[index], coords);
        }
Exemple #6
0
        private static void AddGraph(
            GraphMicrogridLink link,
            GraphCanvas canvas,
            List <Vector2> coords)
        {
            if (coords == null)
            {
                AddGraph(link, canvas);
                return;
            }

            MGMisc.enumToColor.TryGetValue(link.mvar, out Color? colorOverride);
            MGMisc.enumToMetadata.TryGetValue(link.mvar, out string[] s);

            if (colorOverride.HasValue)
            {
                colorOverride = new Color(
                    colorOverride.Value.r,
                    colorOverride.Value.g,
                    colorOverride.Value.b,
                    0.8f);
            }

            string label;

            if (link.graphs.Count > 1)
            {
                int i = link.graphs.Count;
                label = link.mvar.GetVarDescription() + " " + i;
            }
            else
            {
                label = link.mvar.GetVarDescription();
            }

            var graph = new Graph(label, coords)
            {
                colorOverride = colorOverride,
                editable      = link.mvar.IsEditable(),
                valueMetadata = new ValueMetadata(s)
            };

            link.graphs.Add(graph);
            canvas.view.AddGraph(graph);
        }
Exemple #7
0
        private static void UpdateLinkExistingGraph(
            GraphMicrogridLink link,
            Graph graph,
            List <Vector2> coords)
        {
            MGMisc.enumToColor.TryGetValue(link.mvar, out Color? colorOverride);
            MGMisc.enumToMetadata.TryGetValue(link.mvar, out string[] s);

            if (colorOverride.HasValue)
            {
                colorOverride = new Color(
                    colorOverride.Value.r,
                    colorOverride.Value.g,
                    colorOverride.Value.b,
                    0.8f);
            }

            if (link.graphs.Count > 1)
            {
                int i = link.graphs.FindIndex(x => x == graph) + 1;
                graph.label = link.mvar.GetVarDescription() + " " + i;
            }
            else
            {
                graph.label = link.mvar.GetVarDescription();
            }

            if (coords == null)
            {
                coords = new List <Vector2>();
            }

            graph.colorOverride = colorOverride;
            graph.editable      = link.mvar.IsEditable();
            graph.valueMetadata = new ValueMetadata(s);
            graph.SetRawCoords(coords);
            graph.isDirty = true;
        }
Exemple #8
0
 private static void UpdateLinkFromMG(
     GraphMicrogridLink link,
     Microgrid microgrid,
     GraphCanvas canvas)
 {
     if (link.dimensions == 0)
     {
         Debug.LogWarning("Graph can't have zero dimensions.");
         return;
     }
     else if (link.dimensions == 1)
     {
         Update1DFromMG(link, microgrid, canvas);
     }
     else if (link.dimensions == 2)
     {
         Update2DFromMG(link, microgrid, canvas);
     }
     else
     {
         throw new ArgumentException("Trying to get an " +
                                     "unhandled dimension.", nameof(link.dimensions));
     }
 }
Exemple #9
0
 public void AddLink(GraphMicrogridLink link)
 {
     linksMutable.Add(link);
     UpdateLink(link);
 }
Exemple #10
0
        private static void Update2DFromMG(
            GraphMicrogridLink link,
            Microgrid microgrid,
            GraphCanvas canvas)
        {
            int   tCount = microgrid.Input.tCount;
            float tSize  = microgrid.Input.tIncrementSize;

            if (MGMisc.accessor2DArray.ContainsKey(link.mvar))
            {
                if (link.index >= 0)
                {
                    float[,] values = MGMisc.accessor2DArray[link.mvar]
                                      .Get(microgrid);

                    int length = values.GetLength(link.targetDimension);

                    float[][] _values = Arr2DToJaggedArr(values, length,
                                                         link.targetDimension);

                    float[] value;

                    if (_values.GetLength(0) >= link.index + 1)
                    {
                        value = _values[link.index];
                    }
                    else
                    {
                        value = new float[0];
                    }

                    if (link.graphs.Count > 1)
                    {
                        for (int i = link.graphs.Count - 1; i > 0; i--)
                        {
                            canvas.view.RemoveGraph(link.graphs[i]);
                            link.graphs.RemoveAt(i);
                        }

                        UpdateGraph(link, microgrid, value, 0);
                    }
                    else if (link.graphs.Count == 1)
                    {
                        UpdateGraph(link, microgrid, value, 0);
                    }
                    else
                    {
                        AddGraph(link, canvas, value, tCount, tSize);
                    }

                    return;
                }
                else
                {
                    float[,] values = MGMisc.accessor2DArray[link.mvar]
                                      .Get(microgrid);

                    int length = values.GetLength(link.targetDimension);

                    float[][] _values = Arr2DToJaggedArr(values, length,
                                                         link.targetDimension);

                    int graphCount = link.graphs.Count;
                    if (link.graphs.Count > length)
                    {
                        for (int i = graphCount - 1; i >= length; i--)
                        {
                            canvas.view.RemoveGraph(link.graphs[i]);
                            link.graphs.RemoveAt(i);
                        }
                    }
                    else if (link.graphs.Count < length)
                    {
                        for (int i = 0; i < length - graphCount; i++)
                        {
                            AddGraph(link, canvas);
                        }
                    }

                    for (int i = 0; i < length; i++)
                    {
                        UpdateGraph(link, microgrid, _values[i], i);
                    }
                    return;
                }
            }
        }
Exemple #11
0
        private static void SetToMG(
            Microgrid microgrid,
            GraphMicrogridLink link)
        {
            if (MGMisc.accessorLists.ContainsKey(link.mvar))
            {
                if (link.graphs.Count > 0)
                {
                    var values = GetYValues(link.graphs[0].RawCoords);
                    MGMisc.accessorLists[link.mvar].Set(microgrid, values);
                }
            }
            else if (MGMisc.accessor2DArray.ContainsKey(link.mvar))
            {
                float[,] values = MGMisc.accessor2DArray[link.mvar].Get(microgrid);

                int length = values.GetLength(link.targetDimension);

                if (length != link.graphs.Count)
                {
                    return;
                }

                if (link.targetDimension == 0)
                {
                    if (link.index >= 0)
                    {
                        var value = GetYValues(link.graphs[0].RawCoords);
                        MGHelper.SetRow(value, values, link.index);
                    }
                    else
                    {
                        for (int i = 0; i < length; i++)
                        {
                            var value = GetYValues(link.graphs[i].RawCoords);
                            MGHelper.SetRow(value, values, i);
                        }
                    }
                }
                else if (link.targetDimension == 1)
                {
                    if (link.index >= 0)
                    {
                        var value = GetYValues(link.graphs[0].RawCoords);
                        MGHelper.SetCol(value, values, link.index);
                    }
                    else
                    {
                        for (int i = 0; i < length; i++)
                        {
                            var value = GetYValues(link.graphs[i].RawCoords);
                            MGHelper.SetCol(value, values, i);
                        }
                    }
                }
                else if (link.targetDimension < 0)
                {
                    throw new ArgumentException("Trying to set to a " +
                                                "negative dimension.", nameof(link.targetDimension));
                }
                else
                {
                    throw new ArgumentException("Trying to set to an " +
                                                "unhandled dimension.", nameof(link.targetDimension));
                }

                MGMisc.accessor2DArray[link.mvar].Set(microgrid, values);
            }
        }
Exemple #12
0
 private void UpdateLink(GraphMicrogridLink link)
 {
     UpdateLinkFromMG(link, microgrid, graphCanvas);
 }