Esempio n. 1
0
        //Marks a Workplan or Selective with attributes: ["name" (if available), "base_time", "opt_time" (if available), "distance", "children"]
        static void Mark_plan(long wp_id, STEPNCLib.Finder Find, STEPNCLib.AptStepMaker APT, StringBuilder builder, int depth, bool last, ref long count)
        {
            long size = Find.GetNestedExecutableCount(wp_id);
            if (Find.IsWorkplan(wp_id))
            {
            if (count != 0)
            {
                builder.Append(",\n");
                count = 0;
            }

            for (int i = 0; i < depth; i++)
                builder.Append("\t");
            builder.Append("{\"workplan\": {");
            string name = Find.GetExecutableName(wp_id);
            double base_time = Find.GetExecutableBaseTime(wp_id);
            double opt_time = Find.GetExecutableOptimizedTime(wp_id);
            double distance = Find.GetExecutableDistance(wp_id);
            if (name != "")
            {
                builder.Append("\"name\": \"");
                builder.Append(name);
                builder.Append("\", ");
            }
            builder.Append("\"base_time\": ");
            builder.Append(base_time);
            builder.Append(", ");
            if (opt_time != base_time)
            {
                builder.Append("\"opt_time\": ");
                builder.Append(opt_time);
                builder.Append(", ");
            }
            builder.Append("\"distance\": ");
            builder.Append(distance);
            builder.Append(", ");
            builder.Append("\"children\" : [\n");
            }
            else if (Find.IsSelective(wp_id))
            {
            if (count != 0)
            {
                builder.Append(",\n");
                count = 0;
            }

            for (int i = 0; i < depth; i++)
                builder.Append("\t");
            builder.Append("{\"selective\": {");
            string name = Find.GetExecutableName(wp_id);
            double base_time = Find.GetExecutableBaseTime(wp_id);
            double opt_time = Find.GetExecutableOptimizedTime(wp_id);
            double distance = Find.GetExecutableDistance(wp_id);
            if (name != "")
            {
                builder.Append("\"name\": \"");
                builder.Append(name);
                builder.Append("\", ");
            }
            builder.Append("\"base_time\": ");
            builder.Append(base_time);
            builder.Append(", ");
            if (opt_time != base_time)
            {
                builder.Append("\"opt_time\": ");
                builder.Append(opt_time);
                builder.Append(", ");
            }
            builder.Append("\"distance\": ");
            builder.Append(distance);
            builder.Append(", ");
            builder.Append("\"children\" : [\n");
            }
            else {
            Console.WriteLine("ERROR IN STEPNC FILE");
            }
            for (int I = 0; I < size; I++)
            {
            long exe_id = Find.GetNestedExecutableNext(wp_id, I);
            String uu = APT.SetUUID_if_not_set(exe_id);

            String type = Find.GetExecutableType(exe_id);
            //System.Console.WriteLine("Item at " + I + " is a " + type + " has UUID: " + uu);
            if (I == (size - 1))
                last = true;
            else
                last = false;

            if (Find.IsWorkplan(exe_id) || Find.IsSelective(exe_id))
                Mark_plan(exe_id, Find, APT, builder, depth + 1, last, ref count);
            else if (Find.IsWorkingstep(exe_id))
                Mark_step(exe_id, Find, APT, builder, depth + 1, last, ref count);
            }

            for (int i = 0; i < depth; i++)
            builder.Append("\t");
            builder.Append("]}}");
        }