//Serialize a set of rectangles(RectList) to SerializedRects public static SerializedRects RectsToSerializedRects(RectList rectSet) { GridConverter.BuildCircuit(rectSet, false); var sb = new StringBuilder(); bool mode2D = false;// RectsAre2D(rectSet); //Sort the rectlist into sets of rectlists where rects have same properties IEnumerable <List <Rect> > superRects = SuperSortByProperties(rectSet); //Iterate through entire set of rectlists foreach (List <Rect> rectList in superRects) { string rectPropertiesSerialized = SerializeRectProperties(rectList[0].Properties, mode2D); sb.Append(rectPropertiesSerialized); //Iterate through each rect in the set (will all have same properties) //Each will inherit properties values when read later from last properties write foreach (Rect rect in rectList) { string rectSerialized = Transcode64.SerializeRectPointsToString(rect, 1, mode2D); rectSerialized += SerializeCircuitProperties(rectList[0].Properties); sb.Append(rectSerialized); } } //Then return new serialized rect with that string return(new SerializedRects(sb.ToString())); }
//Limits it to 255 strings between carriage returns public static string SerializeLimit255(RectList rectSet) { IEnumerable <List <Rect> > superRects = SuperSortByProperties(rectSet); string str = ""; string runStr = ""; bool mode2D = false;// RectsAre2D(rectSet); foreach (List <Rect> rectList in superRects) { runStr += SerializeRectProperties(rectList[0].Properties, mode2D); foreach (Rect t in rectList) { runStr += Transcode64.SerializeRectPointsToString(t, 1, mode2D); runStr += SerializeCircuitProperties(rectList[0].Properties); if (runStr.Length > 200)//236) { str += runStr + CharLimit255; runStr = SerializeRectProperties(rectList[0].Properties, mode2D); } } } str += runStr + CharLimit255; str = str.TrimEnd('\n') + "\n";//ensure only one \n at end return(str); }