示例#1
0
        private static Header ReadHeader(ref StringReader reader)
        {
            Header        header = new Header();
            int           code;
            string        value;
            ValuePairList pairs = new ValuePairList();

            do
            {
                code  = int.Parse(reader.ReadLine().Trim());
                value = reader.ReadLine().Trim();

                if (code == 0 && value == "ENDSEC")
                {
                    header.AddVariable(pairs);
                    return(header);
                }

                if (code == 9 && pairs.Count > 0)
                {
                    header.AddVariable(pairs);
                    pairs = new ValuePairList();
                }

                pairs.Add(new ValuePair(code, value));
            } while (true);
        }
示例#2
0
        private static List <ValuePairList> ReadEntrys(ref StringReader reader, string tableName)
        {
            int    code;
            string value;

            List <ValuePairList> pairsList = new List <ValuePairList>();

            ValuePairList pairs = new ValuePairList();

            pairs.Add(new ValuePair(0, tableName));

            do
            {
                code  = int.Parse(reader.ReadLine().Trim());
                value = reader.ReadLine().Trim();

                if (code == 0)
                {
                    if (value == "ENDTAB")
                    {
                        pairsList.Add(pairs);
                        return(pairsList);
                    }
                    else
                    {
                        pairsList.Add(pairs);
                        pairs = new ValuePairList();
                    }
                }

                pairs.Add(new ValuePair(code, value));
            } while (true);
        }
示例#3
0
        private static Classes ReadClasses(ref StringReader reader)
        {
            Classes classes = new Classes();
            int     code;
            string  value;

            ValuePairList pairs = new ValuePairList();

            do
            {
                code  = int.Parse(reader.ReadLine().Trim());
                value = reader.ReadLine().Trim();

                if (code == 0 && value == "ENDSEC")
                {
                    classes.AddClass(pairs);
                    return(classes);
                }

                if (code == 0 && pairs.Count > 0 && value == "CLASS")
                {
                    classes.AddClass(pairs);
                    pairs = new ValuePairList();
                }

                pairs.Add(new ValuePair(code, value));
            } while (true);
        }
示例#4
0
        private static Objects ReadObjects(ref StringReader reader)
        {
            Objects objects = new Objects();
            int     code;
            string  value;

            ValuePairList pairs = new ValuePairList();

            do
            {
                code  = int.Parse(reader.ReadLine().Trim());
                value = reader.ReadLine().Trim();

                if (code == 0 && value == "ENDSEC")
                {
                    objects.AddObject(pairs);
                    return(objects);
                }

                if (code == 0 && pairs.Count > 0)
                {
                    objects.AddObject(pairs);
                    pairs = new ValuePairList();
                }

                pairs.Add(new ValuePair(code, value));
            } while (true);
        }
示例#5
0
        private static Entities ReadEntities(ref StringReader reader)
        {
            Entities entities = new Entities();
            int      code;
            string   value;

            ValuePairList pairs = new ValuePairList();

            do
            {
                code  = int.Parse(reader.ReadLine().Trim());
                value = reader.ReadLine().Trim();

                if (code == 0 && value == "ENDSEC")
                {
                    entities.AddEntity(pairs);
                    return(entities);
                }

                if (code == 0 && value != "ENDSEC" && pairs.Count > 0)
                {
                    entities.AddEntity(pairs);
                    pairs = new ValuePairList();
                }

                pairs.Add(new ValuePair(code, value));
            } while (true);
        }
示例#6
0
        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);
        }
示例#7
0
        public void AddObject(ValuePairList obj)
        {
            if (objectList.Count == 0)
            {
                baseDictHandle = obj.Get(5).First();
            }

            objectList.Add(obj.Get(5).First(), obj);
        }
示例#8
0
        private static Header PreLoadHeader(WebAppContext context)
        {
            Header header = new Header();

            ValuePairList insunits = new ValuePairList();

            insunits.Add(new ValuePair(9, "$INSUNITS"));
            insunits.Add(new ValuePair(70, "4"));

            header.AddVariable(insunits);

            float minX = float.PositiveInfinity;
            float minY = float.PositiveInfinity;
            float maxX = float.NegativeInfinity;
            float maxY = float.NegativeInfinity;

            foreach (LayoutData inst in context.sheetLayout)
            {
                DXFShape shape = context.shapes[inst.key].dxfBase;

                float unitScale = context.shapes[inst.key].getUnitScale();

                {
                    float x = float.Parse(shape.header.variableList["$EXTMIN"].Get(10).First()) * unitScale + inst.pos.X;
                    float y = float.Parse(shape.header.variableList["$EXTMIN"].Get(20).First()) * unitScale + inst.pos.Y;

                    minX = (x < minX) ? x : minX;
                    minY = (y < minY) ? y : minY;
                }

                {
                    float x = float.Parse(shape.header.variableList["$EXTMAX"].Get(10).First()) * unitScale + inst.pos.X;
                    float y = float.Parse(shape.header.variableList["$EXTMAX"].Get(20).First()) * unitScale + inst.pos.Y;

                    maxX = (x > maxX) ? x : maxX;
                    maxY = (y > maxY) ? y : maxY;
                }
            }

            ValuePairList extMin = new ValuePairList();

            extMin.Add(new ValuePair(9, "$EXTMIN"));
            extMin.Add(new ValuePair(10, minX.ToString()));
            extMin.Add(new ValuePair(20, minY.ToString()));

            header.AddVariable(extMin);

            ValuePairList extMax = new ValuePairList();

            extMax.Add(new ValuePair(9, "$EXTMAX"));
            extMax.Add(new ValuePair(10, maxX.ToString()));
            extMax.Add(new ValuePair(20, maxY.ToString()));

            header.AddVariable(extMax);

            return(header);
        }
示例#9
0
        private List <float> BuildSPLine(ValuePairList enty)
        {
            List <float> vertexBuffer = new List <float>();

            int cpNum   = int.Parse(enty.Get(73).First());
            int knotNum = int.Parse(enty.Get(72).First());
            int degrees = int.Parse(enty.Get(71).First());

            List <float> cpX   = new List <float>();
            List <float> cpY   = new List <float>();
            List <float> knots = new List <float>();
            List <float> cpW   = new List <float>();

            float lineLength = 0;

            for (int i = 0; i < cpNum; i++)
            {
                cpX.Add(float.Parse(enty.Get(10).ElementAt(i)));
                cpY.Add(float.Parse(enty.Get(20).ElementAt(i)));

                if (0 < i)
                {
                    lineLength += MathF.Sqrt(Math.Abs((cpX[i] - cpX[i - 1]) * 2 + (cpY[i] - cpY[i - 1])) * 2);
                }

                if (enty.Get(41) != null && i < enty.Get(41).Count())
                {
                    cpW.Add(float.Parse(enty.Get(41).ElementAt(i)));
                }
                else
                {
                    cpW.Add(1);
                }
            }

            for (int i = 0; i < knotNum; i++)
            {
                knots.Add(float.Parse(enty.Get(40).ElementAt(i)));
            }

            for (float t = 0; t <= 1; t += 1 / (lineLength))
            {
                vertexBuffer.AddRange(NURBSFunction(cpX, cpY, cpW, degrees, knots, t));
            }

            return(vertexBuffer);
        }
示例#10
0
        private static Tables ReadTables(ref StringReader reader)
        {
            Tables tables = new Tables();
            int    code;
            string value;

            ValuePairList pairs = new ValuePairList();

            Table tempTable = null;

            do
            {
                code  = int.Parse(reader.ReadLine().Trim());
                value = reader.ReadLine().Trim();

                if (value == "ENDSEC")
                {
                    return(tables);
                }

                if (value == "ENDTAB")
                {
                    if (pairs.Count > 0)
                    {
                        tempTable = new Table(pairs);
                        pairs     = new ValuePairList();
                        tables.AddTable(tempTable);
                    }
                }
                else if (code == 0 && pairs.Count > 0)
                {
                    tempTable = new Table(pairs);
                    pairs     = new ValuePairList();

                    foreach (ValuePairList entryPairs in ReadEntrys(ref reader, value))
                    {
                        tempTable.AddEntry(entryPairs);
                    }

                    tables.AddTable(tempTable);
                }
                else
                {
                    pairs.Add(new ValuePair(code, value));
                }
            } while (true);
        }
示例#11
0
        public void AddEntry(ValuePairList entry)
        {
            string key;

            if (entry.Contains(2))
            {
                key = entry.Get(2).First();
            }
            else
            {
                key = entry.Get(3).First();
            }

            if (entries.ContainsKey(key))
            {
                entries[key].Add(entry);
            }
            else
            {
                entries.Add(key, new List <ValuePairList>());
                entries[key].Add(entry);
            }
        }
示例#12
0
 public void AddVariable(ValuePairList variable)
 {
     variableList.Add(variable.Get(9).First(), variable);
 }
示例#13
0
        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());
        }
示例#14
0
 public void AddClass(ValuePairList dXFClass)
 {
     classList.Add(dXFClass.Get(1).First(), dXFClass);
 }
示例#15
0
 public void AddEntity(ValuePairList entity)
 {
     entityList.Add(entity);
 }
示例#16
0
 public void AddBlock(ValuePairList block)
 {
     blockList.Add(block.Get(5).First(), block);
 }
示例#17
0
 public Table(ValuePairList _Pairs)
 {
     entries    = new Dictionary <string, List <ValuePairList> >();
     valuePairs = _Pairs;
 }