ElementView InitView()
        {
            DMSType     type = ModelCodeHelper.GetTypeFromGID(GID);
            ModelCode   mc   = dmsTypeToModelCodeMap[type];
            ElementView v;

            if (ModelCodeHelper.ModelCodeClassIsSubClassOf(mc, ModelCode.SWITCH))
            {
                v = new SwitchView(GID, PubSub);
            }
            else if (ModelCodeHelper.ModelCodeClassIsSubClassOf(mc, ModelCode.POWERSYSTEMRESOURCE))
            {
                v = new PowerSystemResourceView(GID, PubSub);
            }
            else if (type == DMSType.ConnectivityNode)
            {
                v = new ConnectivityNodeView(GID, PubSub);
            }
            else if (type == DMSType.Discrete || type == DMSType.Analog)
            {
                v = new MeasurementView(GID, PubSub);
            }
            else
            {
                v = new IdentifiedObjectView(GID, PubSub);
            }

            return(v);
        }
        bool IsSwitchWithoutSCADA(long switchGID)
        {
            if (!ModelCodeHelper.ModelCodeClassIsSubClassOf(typeToModelCode[ModelCodeHelper.GetTypeFromGID(switchGID)], ModelCode.SWITCH))
            {
                return(false);
            }

            Switch s = Get(switchGID) as Switch;

            if (s == null)
            {
                return(false);
            }

            for (int i = 0; i < s.Measurements.Count; ++i)
            {
                Measurement m = Get(s.Measurements[i]) as Measurement;

                if (m == null)
                {
                    continue;
                }

                if (m.MeasurementType == MeasurementType.SwitchState)
                {
                    return(false);
                }
            }

            return(true);
        }
        Brush GetNodeColor(IdentifiedObject io)
        {
            ModelCode mc;

            if (!dmsTypeToModelCodeMap.TryGetValue(ModelCodeHelper.GetTypeFromGID(io.GID), out mc))
            {
                return(Brushes.SlateGray);
            }

            if (!ModelCodeHelper.ModelCodeClassIsSubClassOf(mc, ModelCode.SWITCH))
            {
                return(GetColor(topology.GetNodeEnergization(io.GID)));
            }

            Switch s = (Switch)io;

            foreach (long measGID in s.Measurements)
            {
                Measurement m = (Measurement)networkModel.Get(measGID);

                if (m == null)
                {
                    continue;
                }

                if (m.MeasurementType == MeasurementType.SwitchState)
                {
                    int value;

                    if (!measurements.GetDiscreteInput(m.GID, out value))
                    {
                        continue;
                    }

                    if (value == 0)
                    {
                        return(Brushes.Green);                          //closed
                    }
                    else
                    {
                        return(Brushes.Blue);                           //open
                    }
                }
            }

            return(Brushes.SlateGray);
        }
Exemple #4
0
        public List <Tuple <long, List <Tuple <long, long> >, List <Tuple <long, long> > > > CalculateLineEnergization()
        {
            List <Tuple <long, List <Tuple <long, long> >, List <Tuple <long, long> > > > sourcesEnergization = new List <Tuple <long, List <Tuple <long, long> >, List <Tuple <long, long> > > >(subGraphs.Count);

            for (int i = 0; i < subGraphs.Count; ++i)
            {
                Stack <Tuple <Node, EEnergization> > stack = new Stack <Tuple <Node, EEnergization> >();
                stack.Push(new Tuple <Node, EEnergization>(subGraphs[i], EEnergization.Energized));
                HashSet <Tuple <long, long> > visitedEnergized = new HashSet <Tuple <long, long> >();
                HashSet <Tuple <long, long> > visitedUnknown   = new HashSet <Tuple <long, long> >();

                while (stack.Count > 0)
                {
                    Tuple <Node, EEnergization> node = stack.Pop();
                    EEnergization energization       = node.Item2;
                    long          gid = node.Item1.IO.GID;

                    if (energization != EEnergization.NotEnergized && ModelCodeHelper.ModelCodeClassIsSubClassOf(dmsTypeToModelCodeMap[ModelCodeHelper.GetTypeFromGID(gid)], ModelCode.SWITCH) && GetSwitchState((Switch)node.Item1.IO))
                    {
                        energization = EEnergization.NotEnergized;
                    }

                    if (energization == EEnergization.NotEnergized)
                    {
                        continue;
                    }

                    if (energization == EEnergization.Energized)
                    {
                        for (int j = node.Item1.AdjacentOffset; j < node.Item1.AdjacentOffset + node.Item1.AdjacentCount; ++j)
                        {
                            Node adjacentNode = adjacency[j];

                            if (adjacentNode == null)
                            {
                                continue;
                            }

                            long adjacentGID        = adjacentNode.IO.GID;
                            Tuple <long, long> line = gid <= adjacentGID ? new Tuple <long, long>(gid, adjacentGID) : new Tuple <long, long>(adjacentGID, gid);

                            if (visitedEnergized.Contains(line))
                            {
                                continue;
                            }

                            stack.Push(new Tuple <Node, EEnergization>(adjacentNode, EEnergization.Energized));

                            visitedEnergized.Add(line);
                            visitedUnknown.Remove(line);
                        }
                    }
                    else
                    {
                        for (int j = node.Item1.AdjacentOffset; j < node.Item1.AdjacentOffset + node.Item1.AdjacentCount; ++j)
                        {
                            Node adjacentNode = adjacency[j];

                            if (adjacentNode == null)
                            {
                                continue;
                            }

                            long adjacentGID        = adjacentNode.IO.GID;
                            Tuple <long, long> line = gid <= adjacentGID ? new Tuple <long, long>(gid, adjacentGID) : new Tuple <long, long>(adjacentGID, gid);

                            if (visitedEnergized.Contains(line) || visitedUnknown.Contains(line))
                            {
                                continue;
                            }

                            stack.Push(new Tuple <Node, EEnergization>(adjacentNode, EEnergization.Unknown));

                            visitedUnknown.Add(line);
                        }
                    }
                }

                sourcesEnergization.Add(new Tuple <long, List <Tuple <long, long> >, List <Tuple <long, long> > >(subGraphs[i].IO.GID, new List <Tuple <long, long> >(visitedEnergized), new List <Tuple <long, long> >(visitedUnknown)));
            }

            return(sourcesEnergization);
        }