Beispiel #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);
                }
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
        private static void MoveCoords(
            Graph graph,
            GraphCanvas graphCanvas,
            Vector2 delta,
            List <ModifiedCoord> changedCoords)
        {
            for (int i = 0; i < changedCoords.Count; i++)
            {
                int iCoord   = changedCoords[i].coordIndex;
                var newCoord = new Vector2(graph.Coords[iCoord].x, graph.Coords[iCoord].y + delta.y);
                graph.SetRawCoord(graphCanvas.PxToRaw(newCoord), iCoord);
            }

            graph.isDirty = true;
        }
Beispiel #4
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);
        }
Beispiel #5
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));
     }
 }
Beispiel #6
0
 protected void Awake()
 {
     timelineController = timelineController ?? FindObjectOfType <PSOTimeline>();
     graphCanvas        = GetComponent <GraphCanvas>();
     timelineController.PSOTimelineChanged += SetDataToGraph;
 }
Beispiel #7
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;
                }
            }
        }