Exemple #1
0
 public void removeNodeFault(INotifyComponentChanged node)
 {
     this.faultPoints.Remove(this.faultPoints.FirstOrDefault(p =>
                                                             ComponentViewModel.compare(p, node)));
     modifyComponent(node, p =>
                     p.State = ComponentState.UnConnected);
 }
 public void updateFaultNode(INotifyComponentChanged node)
 {
     foreach (INotifyComponentChanged notify in listeners)
     {
         if (ComponentViewModel.compare(notify, node))
         {
             notify.State = node.State;
         }
     }
 }
        public void updateComponent(ISet <INotifyComponentChanged> infos)
        {
            /*恢复初始状态*/
            resetAllComponents();
            /*标记加电点*/
            ISet <string> pows = Simulation.getInstance().getPows();

            foreach (string label in pows)
            {
                updatePowMark(label);
            }
            /*标记故障点*/
            ISet <INotifyComponentChanged> faults = Simulation.getInstance().getFaultComponents();

            foreach (INotifyComponentChanged nd in faults)
            {
                updateFaultNode(nd);
            }
            /*将导通的回路标记出来*/
            foreach (INotifyComponentChanged info in infos)
            {
                foreach (INotifyComponentChanged notify in listeners)
                {
                    if (ComponentViewModel.compare(info, notify))
                    {
                        notify.markNode();
                    }
                }
            }
            /*将得电的线圈对应的触点标记为动作,手动断开的开关显示断开*/
            ISet <string> coils    = Simulation.getInstance().getPowCoils();
            ISet <string> switches = Simulation.getInstance().getBrokenSwitches();

            foreach (INotifyComponentChanged notify in listeners)
            {
                if (notify.CptType == ComponentType.ContactOpen && coils.Contains(notify.getHeadNode().Part))
                {
                    notify.connect();
                }
                else if (notify.CptType == ComponentType.ContactClose && coils.Contains(notify.getHeadNode().Part))
                {
                    notify.block();
                }
                else if ((notify.CptType == ComponentType.Breaker || notify.CptType == ComponentType.Switch) &&
                         switches.Contains(notify.getHeadNode().Part))
                {
                    notify.block();
                }
            }
        }
Exemple #4
0
        private void modifyComponent(INotifyComponentChanged node, Action <INotifyComponentChanged> action)
        {
            foreach (INotifyComponentChanged cpt in allCpts)
            {
                if (ComponentViewModel.compare(cpt, node))
                {
                    action(cpt);
                }
            }
            ISet <string> ele = new HashSet <string>();

            while (!powUpRoute(ele))
            {
                ;
            }
        }
        /// <summary>
        /// 去除掉已经在VccToGnd中出现过的支路
        /// </summary>
        private ISet <ShortBranchNode> removeRedundentRoute(ISet <ShortBranchNode> nodes, ISet <ShortBranchNode> total)
        {
            List <List <ShortBranchNode> > routes = getAllRoutes(nodes);
            AppProject app = AppProject.GetInstance();

            if (app.VccToGnd == null)
            {
                app.VccToGnd = getVccToGndBranch();
            }
            ISet <ShortBranchNode>         allNodes = expandBranch(app.VccToGnd.Nodes);
            ISet <INotifyComponentChanged> allcpts  = new HashSet <INotifyComponentChanged>();

            foreach (ShortBranchNode brNode in allNodes)
            {
                foreach (TNodeUI nd in brNode.Uis)
                {
                    allcpts.Add(nd.Info);
                }
            }
            List <ShortBranchNode> bans = new List <ShortBranchNode>();

            foreach (List <ShortBranchNode> rt in routes)
            {
                List <INotifyComponentChanged> infos = new List <INotifyComponentChanged>();
                rt.ForEach(p => p.Uis.ForEach(ui => infos.Add(ui.Info)));
                infos.RemoveAt(infos.Count - 1);
                if (infos.All(p =>
                              allcpts.FirstOrDefault(cpt => ComponentViewModel.compare(cpt, p)) != null
                              ))
                {
                    bans.Add(rt[0]);
                    rt.ForEach(p => total.Remove(p));
                }
            }
            bans.ForEach(p => nodes.Remove(p));
            return(nodes);
        }