Пример #1
0
        /// <summary>
        /// Find all user-created procedure definitions in a workspace.
        /// </summary>
        /// <param name="root">Root workspace.</param>
        /// <returns>Pair of arrays, the first contains procedures without return variables, the
        /// second with. Each procedure is defined by a three-element list of name, parameter
        /// list, and return value boolean.</returns>
        public static Tuple <string, string[], bool>[][] allProcedures(Workspace root)
        {
            var blocks             = root.getAllBlocks();
            var proceduresReturn   = new JsArray <Tuple <string, string[], bool> >();
            var proceduresNoReturn = new JsArray <Tuple <string, string[], bool> >();

            for (var i = 0; i < blocks.Length; i++)
            {
                var block = blocks[i];
                if ((block.type == ProceduresDefnoreturnBlock.type_name) ||
                    (block.type == ProceduresDefreturnBlock.type_name))
                {
                    var tuple = ((ProceduresDefBlock)block).getProcedureDef();
                    if (tuple != null)
                    {
                        if (tuple.Item3)
                        {
                            proceduresReturn.Push(tuple);
                        }
                        else
                        {
                            proceduresNoReturn.Push(tuple);
                        }
                    }
                }
            }
            proceduresNoReturn.Sort(procTupleComparator_);
            proceduresReturn.Sort(procTupleComparator_);
            return(new Tuple <string, string[], bool>[][] { proceduresNoReturn, proceduresReturn });
        }
Пример #2
0
        /// <summary>
        /// Finds the top-level blocks and returns them.  Blocks are optionally sorted
        /// by position; top to bottom (with slight LTR or RTL bias).
        /// </summary>
        /// <param name="ordered">Sort the list if true.</param>
        /// <returns>The top-level block objects.</returns>
        public JsArray <Block> getTopBlocks(bool ordered)
        {
            // Copy the topBlocks_ list.
            var blocks = new JsArray <Block>();

            this.topBlocks_.ForEach((b) => blocks.Push(b));
            if (ordered && blocks.Length > 1)
            {
                var offset = System.Math.Sin(goog.math.toRadians(Workspace.SCAN_ANGLE));
                if (this.RTL)
                {
                    offset *= -1;
                }
                blocks.Sort((a, b) => {
                    var aXY = a.getRelativeToSurfaceXY();
                    var bXY = b.getRelativeToSurfaceXY();
                    var aa  = (aXY.y + offset * aXY.x);
                    var bb  = (bXY.y + offset * bXY.x);
                    if (aa == bb)
                    {
                        return(0);
                    }
                    if (aa > bb)
                    {
                        return(1);
                    }
                    else
                    {
                        return(-1);
                    }
                });
            }
            return(blocks);
        }