Пример #1
0
        private void RenderDeviceItemElement(TListData listData, Rect cellRect, Action <TListData> updateAction)
        {
            // sets the item if only one coil
            UpdateDeviceItem(listData);

            var numDeviceItems = listData.DeviceComponent == null ? -1 : listData.DeviceComponent.AvailableDeviceItems.Count();

            // no coils: show error
            if (numDeviceItems == 0)
            {
                var icon     = EditorGUIUtility.IconContent("Error@2x").image;
                var iconRect = cellRect;
                iconRect.width = 20;
                var guiColor = GUI.color;
                GUI.color = Color.clear;
                EditorGUI.DrawTextureTransparent(iconRect, icon, ScaleMode.ScaleToFit);
                GUI.color   = guiColor;
                cellRect.x += 20;

                var s = new GUIStyle(EditorStyles.label)
                {
                    normal = { textColor = new Color(1f, 0.431f, 0.25f) }
                };
                EditorGUI.LabelField(cellRect, "No coils!", s);
                return;
            }

            // only one coil with no description: show nothing
            if (numDeviceItems == 1 && string.IsNullOrEmpty(listData.DeviceComponent !.AvailableDeviceItems.First().Description))
            {
                return;
            }

            // disable if nothing to select
            EditorGUI.BeginDisabledGroup(numDeviceItems <= 1);

            var currentIndex = 0;
            var labels       = Array.Empty <string>();
            IDeviceComponent <TDeviceITem> device = null;

            if (listData.DeviceComponent != null)
            {
                device       = listData.DeviceComponent;
                labels       = device.AvailableDeviceItems.Select(s => s.Description).ToArray();
                currentIndex = device.AvailableDeviceItems.TakeWhile(s => s.Id != listData.DeviceItem).Count();
            }
            EditorGUI.BeginChangeCheck();
            var newIndex = EditorGUI.Popup(cellRect, currentIndex, labels);

            if (EditorGUI.EndChangeCheck() && device != null)
            {
                if (currentIndex != newIndex)
                {
                    listData.DeviceItem = device.AvailableDeviceItems.ElementAt(newIndex).Id;
                    updateAction(listData);
                }
            }
            EditorGUI.EndDisabledGroup();
        }
Пример #2
0
        public bool Compiler()
        {
            bool bResult = true;

            commandRunner = null;
            MethodInfo method = null;

            processedString = originalString;
            bResult        &= findSpecialSymbolsPairs(processedString);
            bResult        &= checkVariablesInPercentSignPairExist();
            if (bResult)
            {
                #region Functions
                if (parenthesisPairs.Count > 0 && parenthesisPairs.Last().LeftIndex > 0 &&
                    (parenthesisPairs.Last().RightIndex == processedString.Length - 1) &&
                    (processedString.Substring(0, parenthesisPairs.Last().LeftIndex).Split(clsOperationString.OperationSymbols, StringSplitOptions.None).Count() == 1)
                    )
                {
                    #region parse command header
                    String cmdTemp = processedString.Substring(0, parenthesisPairs.Last().LeftIndex).Trim();
                    String deviceName = "", componentName = "", methodName = "";
                    bResult &= getCommandHeader(cmdTemp, ref deviceName, ref componentName, ref methodName);
                    if (scriptline.Script.Package.Devices.ContainsKey(deviceName))
                    {
                        if (deviceName.StartsWith(clsPackage.KEY_Device))
                        {
                            IDevice          aDevice  = (IDevice)scriptline.Script.Package.Devices[deviceName];
                            IDeviceComponent aDevComp = null;
                            if (componentName != null && componentName.Length > 0)
                            {
                                aDevComp = (IDeviceComponent)aDevice.DeviceComponents[componentName];
                            }
                            if (aDevComp != null)
                            {
                                commandRunner = aDevComp;
                            }
                            else
                            {
                                bResult = false;
                            }
                        }
                        else  //External components
                        {
                        }
                    }
                    else if (deviceName.Equals(clsPackage.KEY_BasicOperation))
                    {
                        commandRunner = new clsBasicOperations();
                    }
                    else
                    {
                        bResult = false;
                        scriptline.Script.RuntimeErrorMessages.Add(new clsRuntimeErrorMessage(scriptline.LineNumber, deviceName + " does not exist."));
                    }
                    #endregion parse command header

                    #region parse parameters of command
                    int    start      = parenthesisPairs.Last().LeftIndex;
                    int    length     = parenthesisPairs.Last().RightIndex - start;
                    String paramsTemp = processedString.Substring(start, length).TrimStart(new char[] { '(' }).TrimEnd(new char[] { ')' });
                    bResult &= getParametersOfMethod(start, paramsTemp);
                    #endregion parse parameters of command

                    if (bResult)
                    {
                        method = ((IDeviceComponent)commandRunner).GetMethod(methodName, parameters.ToArray());
                        if (method == null)
                        {
                            bResult = false;
                            scriptline.Script.RuntimeErrorMessages.Add(new clsRuntimeErrorMessage(scriptline.LineNumber, methodName + "(params[" + parameters.Count + "]), does not exist."));
                        }
                    }
                }
                #endregion Functions
                #region Operations
                #region Opertaions in parenthesisPairs is the first priority
                else if (parenthesisPairs.Count > 0)
                {
                    for (int i = parenthesisPairs.Count - 1; i >= 0; i--)
                    {
                        if (parenthesisPairs[i].Text.Length > 0)
                        {
                            String     strTempVariable = scriptline.Script.GetNewTempVariableName;
                            clsCommand subOperation    = new clsCommand(scriptline, parenthesisPairs[i].Text, strTempVariable);
                            subCommands.Add(subOperation);
                            processedString = replaceSubString(processedString, "%" + strTempVariable + "%", parenthesisPairs[i].LeftIndex, parenthesisPairs[i].RightIndex);
                        }
                    }
                }
                #endregion Opertaions in parenthesisPairs is the first priority
                bResult &= compilerOperandsAndOperations();
                if (bResult)
                {
                    commandRunner = scriptline.Script.Package.BasicOperations;
                }
                #endregion Operations

                //#region Assignment

                //#endregion Assignment
            }
            foreach (clsCommand subCommand in subCommands)
            {
                bResult &= subCommand.Compiler();
            }
            return(bResult);
        }
 public void AddComponent(IDeviceComponent component)
 {
     _components.Add(component);
 }