コード例 #1
0
        /// <summary>
        /// Копирование доп. свойств базовой операции
        /// </summary>
        /// <param name="newOwner">Новая базовая операция-владелец</param>
        /// <returns></returns>
        private List <BaseParameter> CloneProperties(BaseOperation newOwner)
        {
            var properties = new List <BaseParameter>();

            for (int i = 0; i < baseOperationProperties.Count; i++)
            {
                BaseParameter oldProperty = baseOperationProperties[i];
                BaseParameter newProperty = oldProperty.Clone();
                if (oldProperty.Owner is BaseTechObject)
                {
                    var obj = oldProperty.Owner as BaseTechObject;
                    if (obj.IsAttachable)
                    {
                        newProperty.Owner = oldProperty.Owner;
                    }
                }
                else
                {
                    newProperty.Owner = newOwner;
                }
                properties.Add(newProperty);
            }

            return(properties);
        }
コード例 #2
0
        /// <summary>
        /// Проверка множественных значений в оборудовании
        /// </summary>
        /// <param name="devices">Устройства</param>
        /// <param name="equipment">Оборудование</param>
        /// <param name="techObjectName">Имя объекта</param>
        /// <returns></returns>
        private string CheckMultiValue(string[] devices,
                                       BaseParameter equipment, string techObjectName)
        {
            string errors         = "";
            var    unknownDevices = new List <string>();

            foreach (var deviceStr in devices)
            {
                var device = Device.DeviceManager.GetInstance()
                             .GetDeviceByEplanName(deviceStr);
                if (device.Description == StaticHelper.CommonConst.Cap)
                {
                    unknownDevices.Add(deviceStr);
                }
            }

            if (unknownDevices.Count > 0)
            {
                errors = $"Проверьте оборудование: " +
                         $"\"{equipment.Name}\" в объекте " +
                         $"\"{techObjectName}\". " +
                         $"Некорректные устройства: " +
                         $"{string.Join(",", unknownDevices)}.\n";
            }

            return(errors);
        }
コード例 #3
0
        /// <summary>
        /// Копирование объекта
        /// </summary>
        /// <returns></returns>
        public BaseOperation Clone()
        {
            var properties = new List <BaseParameter>(baseOperationProperties
                                                      .Count);
            var operation = EmptyOperation();

            for (int i = 0; i < baseOperationProperties.Count; i++)
            {
                BaseParameter oldProperty = baseOperationProperties[i];
                BaseParameter newProperty = oldProperty.Clone();
                if (oldProperty.Owner is BaseTechObject)
                {
                    var obj = oldProperty.Owner as BaseTechObject;
                    if (obj.IsAttachable)
                    {
                        newProperty.Owner = oldProperty.Owner;
                    }
                }
                else
                {
                    newProperty.Owner = operation;
                }
                properties.Add(newProperty);
            }

            var steps = new List <BaseStep>();

            for (int i = 0; i < Steps.Count; i++)
            {
                var newStep = Steps[i].Clone();
                newStep.Owner = operation;
                steps.Add(newStep);
            }

            operation.Name            = operationName;
            operation.LuaName         = luaOperationName;
            operation.Properties      = properties;
            operation.Steps           = steps;
            operation.owner           = this.Owner;
            operation.DefaultPosition = DefaultPosition;

            operation.SetItems();

            return(operation);
        }
コード例 #4
0
        public override bool SetNewValue(string newVal, bool isExtraValue)
        {
            State state = this.Owner;

            Step equalStep = state.Steps
                             .Where(x => x.GetBaseStepName() == newVal)
                             .FirstOrDefault();

            if (equalStep == null)
            {
                equalStep = state.Steps
                            .Where(x => x.GetBaseStepLuaName() == newVal)
                            .FirstOrDefault();
            }

            if (equalStep != null && newVal != "")
            {
                return(false);
            }

            Mode          mode     = state.Owner;
            BaseParameter baseStep = mode.BaseOperation.Steps
                                     .Where(x => x.LuaName == newVal).FirstOrDefault();

            if (baseStep == null)
            {
                baseStep = mode.BaseOperation.Steps
                           .Where(x => x.Name == newVal).FirstOrDefault();
            }

            if (baseStep != null)
            {
                this.baseStep = new ActiveParameter(baseStep.LuaName,
                                                    baseStep.Name);
                this.baseStep.Owner = this;
                if (name.Contains(NewStepName) && baseStep.Name != "")
                {
                    name = baseStep.Name;
                }

                return(true);
            }

            return(false);
        }
コード例 #5
0
        /// <summary>
        /// Проверка пустых не отключенных параметров агрегатов
        /// </summary>
        /// <param name="property">Свойство</param>
        /// <param name="errors">Список ошибок</param>
        private void CheckNotEmptyDisabledAggregateProperties(
            BaseParameter property, ref string errors)
        {
            bool notEmptyDisabledAggregateProperty =
                property.Owner is BaseTechObject &&
                !property.Disabled &&
                (property.Value == "");

            if (notEmptyDisabledAggregateProperty)
            {
                string modeName    = owner.DisplayText[0];
                string techObjName = Owner.Owner.Owner.DisplayText[0];
                string message     = $"Свойство \"{property.Name}\" в " +
                                     $"операции \"{modeName}\", объекта \"{techObjName}\"" +
                                     $" не заполнено.\n";
                errors += message;
            }
        }
コード例 #6
0
        /// <summary>
        /// Проверить параметры и устройства для ПИД
        /// </summary>
        /// <param name="equipment">Оборудование</param>
        /// <returns></returns>
        private string CheckEquipmentValues(BaseParameter equipment)
        {
            var    errors         = "";
            string techObjectName = owner.DisplayText[0];
            string currentValue   = equipment.Value;

            string[] devices = currentValue.Split(' ');
            if (devices.Length > 1)
            {
                errors += CheckMultiValue(devices, equipment, techObjectName);
            }
            else
            {
                errors += CheckSingleValue(currentValue, equipment,
                                           techObjectName);
            }

            return(errors);
        }
コード例 #7
0
        /// <summary>
        /// Установка устройств в оборудовании автоматически
        /// </summary>
        /// <param name="equipment">Оборудование</param>
        private void SetDeviceAutomatically(BaseParameter equipment)
        {
            string currentValue = equipment.Value;

            if (equipment.DefaultValue != "" &&
                currentValue == equipment.DefaultValue)
            {
                string deviceName = owner.NameEplan + owner.TechNumber +
                                    equipment.DefaultValue;
                var device = Device.DeviceManager.GetInstance()
                             .GetDevice(deviceName);
                if (device.Description != StaticHelper.CommonConst.Cap)
                {
                    equipment.SetNewValue(deviceName);
                }
                else
                {
                    equipment.SetNewValue("");
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Проверка одиночных значений в оборудовании
        /// </summary>
        /// <param name="currentValue">Текущее значение</param>
        /// <param name="equipment">Оборудование</param>
        /// <param name="techObjectName">Имя объекта</param>
        /// <returns></returns>
        private string CheckSingleValue(string currentValue,
                                        BaseParameter equipment, string techObjectName)
        {
            string errors = "";

            var device = Device.DeviceManager.GetInstance()
                         .GetDeviceByEplanName(currentValue);

            if (equipment.LuaName == "SET_VALUE")
            {
                bool isValid =
                    (device.Description != StaticHelper.CommonConst.Cap ||
                     owner.GetParamsManager().Float
                     .GetParam(currentValue) != null);
                if (!isValid)
                {
                    errors += $"Отсутствует задание для ПИД регулятора" +
                              $" \"{owner.DisplayText[0]}\".\n";
                }
            }
            else
            {
                bool isValid =
                    device.Description != StaticHelper.CommonConst.Cap ||
                    currentValue == "" ||
                    currentValue == equipment.DefaultValue;
                if (!isValid)
                {
                    errors += $"Проверьте оборудование: " +
                              $"\"{equipment.Name}\" в объекте " +
                              $"\"{techObjectName}\". " +
                              $"Некорректное устройство: {currentValue}.\n";
                }
            }

            return(errors);
        }
コード例 #9
0
 /// <summary>
 /// Добавить оборудование.
 /// </summary>
 /// <param name="property">Оборудование</param>
 private void AddItem(BaseParameter property)
 {
     items.Add(property);
     Sort();
 }
コード例 #10
0
        /// <summary>
        /// Получить тип параметра в зависимости от введенного значения в поле
        /// </summary>
        /// <param name="parameter">Параметр для проверки</param>
        /// <returns></returns>
        private ParameterValueType GetParameterValueType(TechObject obj,
                                                         BaseParameter parameter)
        {
            var result         = ParameterValueType.Other;
            var parameterValue = parameter.Value;

            if (parameter.IsBoolParameter)
            {
                result = ParameterValueType.Boolean;
                return(result);
            }

            if (int.TryParse(parameterValue, out _))
            {
                result = ParameterValueType.Number;
                return(result);
            }

            bool isParameter = obj.GetParamsManager()
                               .GetParam(parameterValue) != null;

            if (isParameter)
            {
                result = ParameterValueType.Parameter;
                return(result);
            }

            var  deviceManager = Device.DeviceManager.GetInstance();
            bool isDevice      = deviceManager.GetDeviceByEplanName(parameterValue)
                                 .Description != StaticHelper.CommonConst.Cap;

            if (isDevice)
            {
                result = ParameterValueType.Device;
                return(result);
            }

            string[] devices = parameterValue.Split(' ');
            if (devices.Length > 1)
            {
                bool haveBadDevices = false;
                var  validDevices   = new List <bool>();
                foreach (var device in devices)
                {
                    isDevice = deviceManager.GetDeviceByEplanName(device)
                               .Description != StaticHelper.CommonConst.Cap;
                    if (isDevice == false)
                    {
                        haveBadDevices = true;
                    }
                    validDevices.Add(isDevice);
                }

                validDevices = validDevices.Distinct().ToList();
                if (validDevices.Count == 1 && haveBadDevices == false)
                {
                    result = ParameterValueType.ManyDevices;
                    return(result);
                }
            }

            bool stub = parameter.Value.ToLower()
                        .Contains(StaticHelper.CommonConst.StubForCells.ToLower());

            if (stub)
            {
                result = ParameterValueType.Stub;
                return(result);
            }

            return(result);
        }
コード例 #11
0
        /// <summary>
        /// Получение строки для сохранения в зависимости от того, кто
        /// владеет параметром. Сам юнит или это параметр агрегата.
        /// </summary>
        /// <param name="parameter">Параметр для обработки</param>
        /// <param name="prefix">Отступ</param>
        /// <param name="mainObjMode">Проверяемая операция главного объекта
        /// </param>
        /// <returns></returns>
        public string GetNumberParameterStringForSave(string prefix,
                                                      BaseParameter parameter, Mode mainObjMode)
        {
            BaseTechObject baseTechObject = null;
            List <Mode>    modes          = new List <Mode>();
            string         mainObjName    = "";

            if (parameter.Owner is BaseTechObject)
            {
                baseTechObject = parameter.Owner as BaseTechObject;
                mainObjName    = $"{baseTechObject.Owner.DisplayText[0]}";
                modes          = baseTechObject.Owner.ModesManager.Modes;
            }

            if (parameter.Owner is BaseOperation)
            {
                var operation = parameter.Owner as BaseOperation;
                baseTechObject = operation.Owner.Owner.Owner.BaseTechObject;
                mainObjName    = $"{baseTechObject.Owner.DisplayText[0]}";
                modes          = operation.Owner.Owner.Modes;
            }

            string parameterValue = parameter.Value;
            var    mode           = modes
                                    .Where(x => x.GetModeNumber().ToString() == parameterValue)
                                    .FirstOrDefault();
            var res = "";

            if (mode != null)
            {
                if (mode.BaseOperation.Name != "")
                {
                    parameterValue = mode.BaseOperation.LuaName.ToUpper();
                    TechObject obj     = baseTechObject.Owner;
                    string     objName = "prg." + obj.NameEplanForFile.ToLower() +
                                         obj.TechNumber.ToString();
                    res = $"{prefix}{parameter.LuaName} = " +
                          $"{objName}.operations." + parameterValue + ",\n";
                }
                else
                {
                    string message = $"Ошибка обработки параметра " +
                                     $"\"{parameter.Name}\"." +
                                     $" Не задана базовая операция в операции" +
                                     $" \"{mode.DisplayText[0]}\", объекта " +
                                     $"\"{mainObjName}\".\n";
                    Logs.AddMessage(message);
                }
            }
            else
            {
                string message = $"Ошибка обработки параметра " +
                                 $"\"{parameter.Name}\"." +
                                 $" Указан несуществующий номер операции в операции " +
                                 $"\"{mainObjMode.DisplayText[0]}\" объекта " +
                                 $"\"{mainObjName}\".\n";
                Logs.AddMessage(message);
            }


            return(res);
        }