private static Blocks ReadBlocks(ref StringReader reader) { Blocks blocks = new Blocks(); int code; string value; ValuePairList pairs = new ValuePairList(); do { code = int.Parse(reader.ReadLine().Trim()); value = reader.ReadLine().Trim(); if (code == 0 && value == "ENDSEC") { blocks.AddBlock(pairs); return(blocks); } if (code == 0 && pairs.Count > 0) { blocks.AddBlock(pairs); pairs = new ValuePairList(); } pairs.Add(new ValuePair(code, value)); } while (true); }
public static void Write(WebAppContext context) { Header header = PreLoadHeader(context); Classes classes = new Classes(); Tables tables = new Tables(); Blocks blocks = new Blocks(); Entities entities = new Entities(); Objects objects = new Objects(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); foreach (LayoutData inst in context.sheetLayout) { DXFShape shape = context.shapes[inst.key].dxfBase; foreach (string key in shape.header.variableList.Keys) { if (!header.variableList.ContainsKey(key)) { header.AddVariable(shape.header.variableList[key]); } } if (shape.classes != null) { foreach (string key in shape.classes.classList.Keys) { if (!classes.classList.ContainsKey(key)) { classes.AddClass(shape.classes.classList[key]); } } } foreach (string key in shape.tables.tableList.Keys) { if (!tables.tableList.ContainsKey(key)) { tables.AddTable(shape.tables.tableList[key]); } } if (shape.blocks != null) { foreach (string key in shape.blocks.blockList.Keys) { if (!blocks.blockList.ContainsKey(key)) { blocks.AddBlock(shape.blocks.blockList[key]); } } } foreach (ValuePairList enty in shape.entities.entityList) { ValuePairList tempEnty = new ValuePairList(); float minX = float.Parse(shape.header.variableList["$EXTMIN"].Get(10).First()); float minY = float.Parse(shape.header.variableList["$EXTMIN"].Get(20).First()); float maxX = float.Parse(shape.header.variableList["$EXTMAX"].Get(10).First()); float maxY = float.Parse(shape.header.variableList["$EXTMAX"].Get(20).First()); float unitScale = context.shapes[inst.key].getUnitScale(); foreach (int key in enty.orderdKeys) { foreach (string value in enty.Get(key)) { if ((9 < key && key < 19)) { if (inst.fliped) { tempEnty.Add(new ValuePair(key, (((maxX - float.Parse(value)) * unitScale) + inst.pos.X).ToString())); } else { tempEnty.Add(new ValuePair(key, (((float.Parse(value) - minX) * unitScale) + inst.pos.X).ToString())); } } else if (19 < key && key < 29) { if (inst.fliped) { tempEnty.Add(new ValuePair(key, (((maxY - float.Parse(value)) * unitScale) + inst.pos.Y).ToString())); } else { tempEnty.Add(new ValuePair(key, (((float.Parse(value) - minY) * unitScale) + inst.pos.Y).ToString())); } } else { tempEnty.Add(new ValuePair(key, value)); } } } entities.AddEntity(tempEnty); } if (shape.objects != null) { foreach (string key in shape.objects.objectList.Keys) { if (!objects.objectList.ContainsKey(key)) { objects.AddObject(shape.objects.objectList[key]); } } } } stopwatch.Stop(); context.js.ConsoleLog("Building time taken: " + stopwatch.ElapsedMilliseconds.ToString()); stopwatch.Restart(); LinkedList <char> fileStr = new LinkedList <char>(); if (header.variableList.Count > 0) { AppendLine(context, ref fileStr, "0\nSECTION\n"); AppendLine(context, ref fileStr, "2\nHEADER\n"); foreach (KeyValuePair <string, ValuePairList> keyVar in header.variableList) { AppendLine(context, ref fileStr, keyVar.Value.ReadToFile()); } AppendLine(context, ref fileStr, "0\nENDSEC\n"); } if (classes.classList.Count > 0) { AppendLine(context, ref fileStr, "0\nSECTION\n"); AppendLine(context, ref fileStr, "2\nCLASSES\n"); foreach (KeyValuePair <string, ValuePairList> keyClass in classes.classList) { AppendLine(context, ref fileStr, keyClass.Value.ReadToFile()); } AppendLine(context, ref fileStr, "0\nENDSEC\n"); } if (tables.tableList.Count > 0) { AppendLine(context, ref fileStr, "0\nSECTION\n"); AppendLine(context, ref fileStr, "2\nTABLES\n"); foreach (KeyValuePair <string, Table> keyTable in tables.tableList) { AppendLine(context, ref fileStr, keyTable.Value.valuePairs.ReadToFile()); foreach (List <ValuePairList> entries in keyTable.Value.entries.Values) { foreach (ValuePairList entry in entries) { AppendLine(context, ref fileStr, entry.ReadToFile()); } } AppendLine(context, ref fileStr, "0\nENDTAB\n"); } AppendLine(context, ref fileStr, "0\nENDSEC\n"); } if (blocks.blockList.Count > 0) { AppendLine(context, ref fileStr, "0\nSECTION\n"); AppendLine(context, ref fileStr, "2\nBLOCKS\n"); foreach (ValuePairList block in blocks.blockList.Values) { AppendLine(context, ref fileStr, block.ReadToFile()); } AppendLine(context, ref fileStr, "0\nENDSEC\n"); } if (entities.entityList.Count > 0) { AppendLine(context, ref fileStr, "0\nSECTION\n"); AppendLine(context, ref fileStr, "2\nENTITIES\n"); foreach (ValuePairList enty in entities.entityList) { AppendLine(context, ref fileStr, enty.ReadToFile()); } AppendLine(context, ref fileStr, "0\nENDSEC\n"); } if (objects.objectList.Count > 0) { AppendLine(context, ref fileStr, WriteObjects(objects, GetTableHandles(tables))); } AppendLine(context, ref fileStr, "0\nEOF\n"); context.js.AppendToStorage(IdList.WriterStorageKey, new string(fileStr.ToArray())); stopwatch.Stop(); context.js.ConsoleLog("Writing time take: " + stopwatch.ElapsedMilliseconds.ToString()); }