Beispiel #1
0
		public Line()
		{
			Name = "Название АЛС";
			Devices = new List<Device>();
            IsCircular = false;
            KAU = new Device() { DriverType = DriverType.RSR2_KAU };
		}
Beispiel #2
0
        public DeviceViewModel(Device device, LineViewModel owner)
		{
			Device = device;
            Owner = owner;
            _cableType = Device.Cable.CableType;
			_cableResistivity = Device.Cable.Resistivity;
			_cableLength = Device.Cable.Length;

            Drivers = new ObservableCollection<DriverViewModel>(DriversHelper.Drivers.Where(x => x.CanAdd).Select(x => new DriverViewModel(x)));
            _selectedDriver = Drivers.FirstOrDefault(x => x.Driver.DriverType == Device.DriverType);
		}
Beispiel #3
0
 public DeviceIndicator(Device device, double i, double u)
 {
     Device = device;
     I = i;
     U = u;
 }
Beispiel #4
0
        public static IEnumerable<CableSpecificationItem> GenerateFromSpecification(Configuration configuration, IList<DeviceSpecificationItem> deviceSpecificationItems, IList<CableSpecificationItem> cableSpecificationItems)
		{
            const int maxAdress = 240;
			configuration.Lines = new List<Line>();
			var totalDevicesCount = deviceSpecificationItems.Sum(x => x.Count * x.Driver.Mult);
            for (int i = 0; i <= totalDevicesCount / maxAdress; i++)
            {
                configuration.Lines.Add(new Line());
            }

            var expandedDeviceSpecificationItems = new List<DeviceSpecificationItem>();
            foreach (var deviceSpecificationItem in deviceSpecificationItems)
                for (int i = 0; i < deviceSpecificationItem.Count; i++)
                    expandedDeviceSpecificationItems.Add(new DeviceSpecificationItem() { DriverType = deviceSpecificationItem.DriverType, Count = 1 } );

            var sortedDeviceSpecificationItems = expandedDeviceSpecificationItems.OrderByDescending(x=>x.Driver.DeviceType).ThenBy(x => x.Driver.I);

            bool needAnotherLine = false;
            for (int i = 0; i < configuration.Lines.Count; i++)
			{
                uint sum = 0;
                for (int j = i; j < expandedDeviceSpecificationItems.Count; j+=configuration.Lines.Count)
                    sum += expandedDeviceSpecificationItems[j].Driver.Mult;

                if (sum > maxAdress)
                {
                    needAnotherLine = true;
                    break;
                }
            }

            if (needAnotherLine)
                configuration.Lines.Add(new Line());

            var lineNo = 0;
			foreach (var deviceSpecificationItem in sortedDeviceSpecificationItems)
			{
				var line = configuration.Lines[lineNo];
				lineNo++;
				if (lineNo >= configuration.Lines.Count)
					lineNo = 0;
                
                var device = new Device();
				device.DriverType = deviceSpecificationItem.DriverType;
                device.Cable.Length = 0;
                device.Cable.Resistivity = 0;
				line.Devices.Add(device);
				
			}
              
            //Cables
            var cableRemains = 
                cableSpecificationItems.OrderBy(x => x.Resistivity)
                .Select(x => new CableSpecificationItem() { CableType = x.CableType, Length = x.Length, Resistivity = x.Resistivity })
                .ToList();
            var cablePieces = new List<CableSpecificationItem>();
                        
            do
            {
                bool goAgain = false;
                var totalCableLength = cableRemains.Sum(x => x.Length);
                var averageCableLength = totalCableLength / (expandedDeviceSpecificationItems.Count - cablePieces.Count);
                if (averageCableLength > 1000)
                    averageCableLength = 1000;

                for (int i = cableRemains.Count - 1; i >= 0 && cablePieces.Count < expandedDeviceSpecificationItems.Count; i--)
                {
                    if (cableRemains[i].Length < averageCableLength)
                    {
                        goAgain = true;
                        cablePieces.Add(cableRemains[i]);
                        cableRemains.RemoveAt(i);
                        if (i < cableRemains.Count) 
                            i++;
                    }
                }

                if (cablePieces.Count >= expandedDeviceSpecificationItems.Count)
                    break;

                if (goAgain)
                    continue;

                int piecesCount = 0;
                int selectedIndex = 0;
                double maxPieceLength = -1;
                for (int i = cableRemains.Count - 1; i >= 0; i--)
                {
                    int pc;
                    if (cableRemains.Count == 1)
                        pc = expandedDeviceSpecificationItems.Count - cablePieces.Count;
                    else 
                        pc = cableRemains[i].Length % averageCableLength == 0 ? (int)(cableRemains[i].Length / averageCableLength) : (int)(cableRemains[i].Length / averageCableLength) + 1;
                    
                    double pieceLength = cableRemains[i].Length / pc;
                    if (pieceLength > 1000)
                        pieceLength = 1000;

                    if (pieceLength > maxPieceLength)
                    {
                        maxPieceLength = pieceLength;
                        selectedIndex = i;
                        piecesCount = pc;
                    }
                }

                for (int i = 0; i < piecesCount; i++)
                    cablePieces.Add(new CableSpecificationItem() { Length = maxPieceLength, Resistivity = cableRemains[selectedIndex].Resistivity, CableType = cableRemains[selectedIndex].CableType });

                if (selectedIndex < cableRemains.Count)
                {
                    cableRemains[selectedIndex].Length -= maxPieceLength * piecesCount;
                    if (cableRemains[selectedIndex].Length <= 0)
                        cableRemains.RemoveAt(selectedIndex);
                }

            } while (cablePieces.Count < expandedDeviceSpecificationItems.Count);


            var sortedCablePieces = cablePieces.OrderByDescending(x => x.Resistivity).ThenBy(x => x.Length).ToList();

            lineNo = 0;
            var deviceNo = 0;

            foreach (var cablePiece in cablePieces)
            {
                var line = configuration.Lines[lineNo];
                
                if (deviceNo < line.Devices.Count)
                {
                    line.Devices[deviceNo].Cable.Length = cablePiece.Length;
                    line.Devices[deviceNo].Cable.Resistivity = cablePiece.Resistivity;
                    line.Devices[deviceNo].Cable.CableType = cablePiece.CableType;
                }

                if (++lineNo >= configuration.Lines.Count)
                {
                    lineNo = 0;
                    deviceNo++;
                }    

            }

            return cableRemains;
		}
Beispiel #5
0
 static void InsertSupplier(Line line, int index)
 {
     var supplier = new Device();
     supplier.DriverType = DriverType.RSR2_MP;
     supplier.Cable.CableType = line.Devices[index].Cable.CableType;
     supplier.Cable.Length = line.Devices[index].Cable.Length;
     supplier.Cable.Resistivity = line.Devices[index].Cable.Resistivity;
     line.Devices.Insert(index, supplier);
 }
Beispiel #6
0
		void OnPaste()
		{
			var maxAddress = GetMaxAddress();
			var newMaxAddress = maxAddress + DevicesToCopy.Sum(x => x.Driver.Mult);
			if (newMaxAddress > 255)
			{
				MessageBoxService.ShowWarning("Количество устройств на шлейфе не должно превышать 255");
				return;
			}
            var firstIndex = Devices.IndexOf(SelectedDevice);
			foreach (var deviceToCopy in DevicesToCopy)
			{
				var selectedIndex = Devices.IndexOf(SelectedDevice);
                if (selectedIndex < 0) selectedIndex = 0;

				var device = new Device();
				device.DriverType = deviceToCopy.DriverType;
                device.Cable.CableType = deviceToCopy.Cable.CableType;
				device.Cable.Resistivity = deviceToCopy.Cable.Resistivity;
				device.Cable.Length = deviceToCopy.Cable.Length;
				Line.Devices.Insert(selectedIndex, device);
				var deviceViewModel = new DeviceViewModel(device, this);
				Devices.Insert(selectedIndex, deviceViewModel);
				SelectedDevice = deviceViewModel;
			}
			UpdateAddresses(firstIndex - 1);
            Calculate();
		}
Beispiel #7
0
		void OnAdd()
		{
			var newDeviceViewModel = new NewDeviceViewModel();
			if (DialogService.ShowModalWindow(newDeviceViewModel))
			{
				var maxAddress = GetMaxAddress();
				var driver = DriversHelper.GetDriver(newDeviceViewModel.SelectedDriver.DriverType);
				var newMaxAddress = maxAddress + driver.Mult * newDeviceViewModel.Count;
				if (newMaxAddress > 255)
				{
					MessageBoxService.ShowWarning("Количество устройств на шлейфе не должно превышать 255");
					return;
				}

				var selectedIndex = Devices.IndexOf(SelectedDevice) + 1;
                DeviceViewModel deviceViewModel = null;
                for (int i = 0; i < newDeviceViewModel.Count; i++)
				{
					var device = new Device();
                    device.DriverType = newDeviceViewModel.SelectedDriver.DriverType;
                    device.Cable.CableType = newDeviceViewModel.SelectedCableType;
                    device.Cable.Resistivity = newDeviceViewModel.CableResistivity;
					device.Cable.Length = newDeviceViewModel.CableLength;
					Line.Devices.Insert(selectedIndex, device);
					deviceViewModel = new DeviceViewModel(device, this);
					Devices.Insert(selectedIndex, deviceViewModel);
				}
                SelectedDevice = deviceViewModel;
                UpdateAddresses(selectedIndex - 1);
                Calculate();
			}
		}
Beispiel #8
0
        public void InstallPatch(IEnumerable<int> patch)
        {
            foreach(int index in patch)
            {
                var supplier = new Device();
                supplier.DriverType = DriverType.RSR2_MP; 
                supplier.Cable.CableType = Devices[index].CableType;
                supplier.Cable.Resistivity = Devices[index].CableResistivity;
                supplier.Cable.Length = Devices[index].CableLength;

                Line.Devices.Insert(index, supplier);
                Devices.Insert(index, new DeviceViewModel(supplier, this));
            }
            UpdateAddresses();
            Calculate();
        }