示例#1
0
        /// <summary>Returns all MasterCopies in folder as TreeViewItems</summary>
        /// <param name="folder">The folder.</param>
        /// <returns>TreeViewItem</returns>
        /// <exception cref="System.ArgumentNullException">Parameter is null;folder</exception>
        public static TreeViewItem GetMasterCopiesTreeView(MasterCopyFolder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException(nameof(folder), "Parameter is null");
            }

            var treeViewItem = new TreeViewItem();

            treeViewItem.Header = OpennessHelper.GetObjectName(folder);
            treeViewItem.Tag    = folder;

            foreach (var mCopy in folder.MasterCopies)
            {
                var sub = new TreeViewItem();
                sub.Header = mCopy.Name;
                sub.Tag    = mCopy;

                treeViewItem.Items.Add(sub);
            }

            foreach (var subfolder in folder.Folders)
            {
                var subView = GetMasterCopiesTreeView(subfolder);

                treeViewItem.Items.Add(subView);
            }

            return(treeViewItem);
        }
        /// <summary>
        /// Transform excel sheet in a matrix
        /// </summary>
        /// <param name="xlWorksheet"></param>
        public static object[,] ExcelToMatrix(Worksheet xlWorksheet)
        {
            var lastRow = xlWorksheet.Cells.Find("*", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value,
                                                 XlSearchOrder.xlByRows, XlSearchDirection.xlPrevious, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value).Row;

            var lastCol = xlWorksheet.Cells.Find("*", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value,
                                                 XlSearchOrder.xlByColumns, XlSearchDirection.xlPrevious, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value).Column;

            var min = xlWorksheet.Range["A1"];
            var max = xlWorksheet.Range[OpennessHelper.ColumnIndexToColumnLetter(lastCol) + "" + lastRow];

            Range currentRange = xlWorksheet.get_Range(min, max).Cells;

            object[,] matrix = (object[, ])currentRange.Value;

            return(matrix);
        }
        /// <summary>
        /// Look for a device on EPlan PDF and returns it's information
        /// </summary>
        /// <param name="path"></param>
        /// <param name="deviceFGroup"></param>
        /// <param name="deviceIdentifier"></param>
        /// <param name="garetelistPages"></param>
        /// <returns>HW Information</returns>
        public static List <List <string> > HWInfo(string path, string deviceFGroup, string deviceIdentifier, List <int> garetelistPages)
        {
            StringBuilder         text          = new StringBuilder();
            List <List <string> > HWInformation = null;

            string[] delim = { Environment.NewLine, "\n" };
            string[] lines;

            List <int> pages = OpennessHelper.GetPagesByString(path, "=" + deviceFGroup, garetelistPages);

            // If pages list has elements
            if (pages.Any())
            {
                text          = OpennessHelper.ReadPdf(path, pages);
                lines         = text.ToString().Split(delim, StringSplitOptions.None);
                HWInformation = OpennessHelper.GetHWRawInformation(lines, deviceFGroup, deviceIdentifier);
            }

            return(HWInformation);
        }
示例#4
0
        /// <summary>
        /// Adds all objects in the provided folder as TreeViewItems to the provided treeViewItem
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <param name="treeViewItem">The tree view item.</param>
        private static void RecursiveGetTreeView(IEngineeringInstance folder, ref TreeViewItem treeViewItem)
        {
            treeViewItem.Header = OpennessHelper.GetObjectName(folder);
            treeViewItem.Tag    = folder;

            foreach (var item in OpennessHelper.GetSubItem(folder))
            {
                var sub = new TreeViewItem();
                sub.Header = OpennessHelper.GetObjectName(item as IEngineeringInstance);
                sub.Tag    = item;

                if (!(item is Cycle && (item as Cycle).IsSystemObject))
                {
                    treeViewItem.Items.Add(sub);
                }
            }

            foreach (var subfolder in OpennessHelper.GetSubFolder(folder))
            {
                var subView = new TreeViewItem();
                RecursiveGetTreeView(subfolder as IEngineeringInstance, ref subView);
                treeViewItem.Items.Add(subView);
            }
        }
        /// <summary>
        /// Get robot safe range monitoring  from sheet
        /// </summary>
        /// <param name="matrix"></param>
        /// <param name="lastCellRange"></param>
        /// <returns>List with the input properties[0] and output properties[1]</returns>
        public static List <List <RobotSafeRangeMonitoring> > GetRobotSafeRangeMonitoring(object[,] matrix, Range lastCellRange)
        {
            var        SafeRangeMonitoring = new List <List <RobotSafeRangeMonitoring> >();
            var        RobotProperties     = new List <RobotSafeRangeMonitoring>();
            List <int> FirstTextCell       = OpennessHelper.TextPosInRow(matrix, lastCellRange);
            int        row         = FirstTextCell[0];
            int        col         = FirstTextCell[1];
            int        colSymbol   = 0;
            int        colDataType = 0;
            int        colAddress  = 0;
            int        colComment  = 0;

            #region Get outputs
            // Get column numbers
            for (int i = col; i <= lastCellRange.Column; i++)
            {
                string cellVal = Convert.ToString(matrix[row, i]);

                if (string.IsNullOrEmpty(cellVal))
                {
                    break;
                }
                else if (cellVal.ToLower() == "symbol")
                {
                    colSymbol = i;
                }
                else if (cellVal.ToLower() == "datentyp")
                {
                    colDataType = i;
                }
                else if (cellVal.ToLower() == "adresse")
                {
                    colAddress = i;
                }
                else if (cellVal.ToLower() == "kommentar")
                {
                    colComment = i;
                }
            }

            // Get robot properties
            for (int i = row + 1; i <= lastCellRange.Row; i++)
            {
                string cellVal = Convert.ToString(matrix[i, colSymbol]);
                if (!string.IsNullOrEmpty(cellVal))
                {
                    string symbol   = matrix[i, colSymbol].ToString();
                    string dataType = matrix[i, colDataType].ToString();
                    string address  = matrix[i, colAddress].ToString();
                    string comment  = matrix[i, colComment].ToString();

                    RobotProperties.Add(new RobotSafeRangeMonitoring(symbol, dataType, address, comment));
                }
            }
            #endregion region

            SafeRangeMonitoring.Add(RobotProperties);
            RobotProperties = new List <RobotSafeRangeMonitoring>();  // RESET LIST

            #region Get inputs
            // Get inputs start column
            for (int i = col; i <= lastCellRange.Column; i++)
            {
                if (string.IsNullOrEmpty(Convert.ToString(matrix[row, i])))
                {
                    col = i + 1;
                    break;
                }
            }

            // Get column numbers
            for (int i = col; i <= lastCellRange.Column; i++)
            {
                string cellVal = Convert.ToString(matrix[row, i]);

                if (string.IsNullOrEmpty(cellVal))
                {
                    break;
                }
                else if (cellVal.ToLower() == "symbol")
                {
                    colSymbol = i;
                }
                else if (cellVal.ToLower() == "datentyp")
                {
                    colDataType = i;
                }
                else if (cellVal.ToLower() == "adresse")
                {
                    colAddress = i;
                }
                else if (cellVal.ToLower() == "kommentar")
                {
                    colComment = i;
                }
            }

            // Get robot properties
            for (int i = row + 1; i <= lastCellRange.Row; i++)
            {
                string cellVal = Convert.ToString(matrix[i, colSymbol]);
                if (!string.IsNullOrEmpty(cellVal))
                {
                    string symbol   = matrix[i, colSymbol].ToString();
                    string dataType = matrix[i, colDataType].ToString();
                    string address  = matrix[i, colAddress].ToString();
                    string comment  = matrix[i, colComment].ToString();

                    RobotProperties.Add(new RobotSafeRangeMonitoring(symbol, dataType, address, comment));
                }
            }
            #endregion

            SafeRangeMonitoring.Add(RobotProperties);

            return(SafeRangeMonitoring);
        }
        /// <summary>
        /// Get robot teclonogies from sheet
        /// </summary>
        /// <param name="matrix"></param>
        /// <param name="lastCellRange"></param>
        /// <param name="type"></param>
        /// <returns>List with the input properties[0] and output properties[1]</returns>
        public static List <List <RobotTecnologie> > GetRobotTecnologies(object[,] matrix, Range lastCellRange, string type)
        {
            var        Tecnologies = new List <List <RobotTecnologie> >();
            var        RobotTecnologieProperties = new List <RobotTecnologie>();
            List <int> FirstTextCell             = OpennessHelper.TextPosInRow(matrix, lastCellRange);
            int        row              = FirstTextCell[0];
            int        col              = FirstTextCell[1];
            int        colSymbolInputs  = 0;
            int        colSymbolOutputs = 0;
            int        colDataType      = 0;
            int        colAddress       = 0;
            int        colComment       = 0;

            #region Get outputs
            // Get column numbers
            for (int i = col; i <= lastCellRange.Column; i++)
            {
                string cellVal = Convert.ToString(matrix[row, i]);

                if (string.IsNullOrEmpty(cellVal))
                {
                    break;
                }
                else if (cellVal.ToLower() == "symbolik")
                {
                    colSymbolOutputs = i;
                }
                else if (cellVal.ToLower() == "datentyp")
                {
                    colDataType = i;
                }
                else if (cellVal.ToLower() == "adresse")
                {
                    colAddress = i;
                }
                else if (cellVal.ToLower() == "kommentar")
                {
                    colComment = i;
                }
            }

            // Get tecnologie properties
            for (int i = row + 1; i <= lastCellRange.Row; i++)
            {
                string tecName = Convert.ToString(matrix[i, colSymbolOutputs]);

                if (!tecName.Contains("<<BMK>>") && !string.IsNullOrEmpty(tecName))  //If is a tecnologie name
                {
                    var name = Convert.ToString(matrix[i, colSymbolOutputs]);
                    var fbNr = Convert.ToString(matrix[i, lastCellRange.Column]);

                    for (int x = i + 1; x <= lastCellRange.Row; x++)
                    {
                        string cellVal = Convert.ToString(matrix[x, colSymbolOutputs]);

                        if (!string.IsNullOrEmpty(cellVal) && cellVal.Contains("<<BMK>>"))
                        {
                            string symbol   = matrix[x, colSymbolOutputs].ToString();
                            string dataType = matrix[x, colDataType].ToString();
                            string address  = matrix[x, colAddress].ToString();
                            string comment  = matrix[x, colComment].ToString();

                            RobotTecnologieProperties.Add(new RobotTecnologie(fbNr, name, type, symbol, dataType, address, comment));
                        }
                        else
                        {
                            break;
                        }
                        i++;
                    }
                }
            }
            #endregion

            Tecnologies.Add(RobotTecnologieProperties);
            RobotTecnologieProperties = new List <RobotTecnologie>();  // RESET LIST

            #region Get inputs
            // Get inputs start column
            for (int i = col; i <= lastCellRange.Column; i++)
            {
                if (string.IsNullOrEmpty(Convert.ToString(matrix[row, i])))
                {
                    col = i + 1;
                    break;
                }
            }

            // Get column numbers
            for (int i = col; i <= lastCellRange.Column; i++)
            {
                string cellVal = Convert.ToString(matrix[row, i]);

                if (string.IsNullOrEmpty(cellVal))
                {
                    break;
                }
                else if (cellVal.ToLower() == "symbolik")
                {
                    colSymbolInputs = i;
                }
                else if (cellVal.ToLower() == "datentyp")
                {
                    colDataType = i;
                }
                else if (cellVal.ToLower() == "adresse")
                {
                    colAddress = i;
                }
                else if (cellVal.ToLower() == "kommentar")
                {
                    colComment = i;
                }
            }

            // Get robot properties
            for (int i = row + 1; i <= lastCellRange.Row; i++)
            {
                string tecName = Convert.ToString(matrix[i, colSymbolOutputs]);

                if (!tecName.Contains("<<BMK>>") && !string.IsNullOrEmpty(tecName))  //If is a tecnologie name
                {
                    var name = Convert.ToString(matrix[i, colSymbolOutputs]);
                    var fbNr = Convert.ToString(matrix[i, lastCellRange.Column - 1]);

                    for (int x = i + 1; x <= lastCellRange.Row; x++)
                    {
                        string cellVal = Convert.ToString(matrix[x, colSymbolInputs]);

                        if (!string.IsNullOrEmpty(cellVal) && cellVal.Contains("<<BMK>>"))
                        {
                            string symbol   = matrix[x, colSymbolInputs].ToString();
                            string dataType = matrix[x, colDataType].ToString();
                            string address  = matrix[x, colAddress].ToString();
                            string comment  = matrix[x, colComment].ToString();

                            RobotTecnologieProperties.Add(new RobotTecnologie(fbNr, name, type, symbol, dataType, address, comment));
                        }
                        else
                        {
                            break;
                        }
                        i++;
                    }
                }
            }
            #endregion

            Tecnologies.Add(RobotTecnologieProperties);

            return(Tecnologies);
        }