Example #1
0
        private void InitializeObserverWithCurrentSystem(ISystemObserver observer)
        {
            if (_system == null)
            {
                return;
            }

            observer.BeginInitialize();

            ReadOnlySignalSet allSignals = _system.GetAllSignals();

            for (int i = 0; i < allSignals.Count; i++)
            {
                observer.OnSignalAdded(allSignals[i], i);
            }

            ReadOnlyBusSet allBuses = _system.GetAllBuses();

            for (int i = 0; i < allBuses.Count; i++)
            {
                observer.OnBusAdded(allBuses[i], i);
            }

            ReadOnlyPortSet allPorts = _system.GetAllPorts();

            for (int i = 0; i < allPorts.Count; i++)
            {
                observer.OnPortAdded(allPorts[i], i);
            }

            for (int i = 0; i < allSignals.Count; i++)
            {
                Signal s = allSignals[i];
                if (s.IsDriven && allPorts.Contains(s.DrivenByPort))
                {
                    observer.OnPortDrivesSignal(s, s.DrivenByPort, s.DrivenByPort.OutputSignals.IndexOf(s));
                }
            }
            for (int i = 0; i < allPorts.Count; i++)
            {
                Port p = allPorts[i];
                for (int j = 0; j < p.InputSignalCount; j++)
                {
                    Signal s = p.InputSignals[j];
                    if (allSignals.Contains(s))
                    {
                        observer.OnSignalDrivesPort(s, p, j);
                    }
                }
            }

            ReadOnlySignalSet inputs = _system.GetAllInputs();

            for (int i = 0; i < inputs.Count; i++)
            {
                observer.OnInputAdded(inputs[i], i);
            }

            ReadOnlySignalSet outputs = _system.GetAllOutputs();

            for (int i = 0; i < outputs.Count; i++)
            {
                observer.OnOutputAdded(outputs[i], i);
            }

            observer.EndInitialize();
        }