Exemplo n.º 1
0
        /// <summary>
        /// Constructs a sketch from the given stream
        /// </summary>
        /// <param name="reader">The XML reader that will read in XML data</param>
        private void CreateSketch(XmlTextReader reader)
        {
            // Read all the data from the XML file
            this.ReadSketchData(reader);

            List <Shape>  shapes  = new List <Shape>();
            List <Stroke> strokes = new List <Stroke>();

            Dictionary <Guid, Stroke>    allStrokes    = new Dictionary <Guid, Stroke>();
            Dictionary <Guid, Substroke> allSubstrokes = new Dictionary <Guid, Substroke>();
            Dictionary <Guid, Shape>     allShapes     = new Dictionary <Guid, Shape>();

            // Cycle through the Stroke Id's pulled from the file

            foreach (KeyValuePair <Guid, XmlStructs.XmlShapeAttrs> stroke in this.strokeToAttrs)
            {
                XmlStructs.XmlShapeAttrs strokeAttrs = stroke.Value;
                List <Guid> substrokeIds             = this.strokeToSubstrokeIDs[stroke.Key];

                List <Substroke> substrokes = new List <Substroke>();

                // Cycle through the Substroke Id's pulled from the file
                int len = substrokeIds.Count;
                // Check if the file had no strokes.
                if (len == 0)
                {
                    Console.WriteLine("ERROR: File contains no strokes");
                }
                for (int i = 0; i < len; ++i)
                {
                    List <Guid> ptsArray = this.substrokeToPointIDs[substrokeIds[i]];
                    XmlStructs.XmlShapeAttrs substrokeAttrs = this.substrokeToAttrs[substrokeIds[i]];

                    List <Point> points = new List <Point>();

                    // Get all of the Points associated with the Substroke
                    int len2 = ptsArray.Count;
                    for (int k = 0; k < len2; ++k)
                    {
                        points.Add(this.pointsHT[ptsArray[k]]);
                    }

                    // Create a new Substroke and add it to the local Hashtable and Stroke ArrayList
                    Substroke newSubstroke = new Substroke(points, substrokeAttrs);

                    allSubstrokes.Add(newSubstroke.XmlAttrs.Id, newSubstroke);
                    substrokes.Add(newSubstroke);
                }

                // Add a new Stroke
                Stroke newStroke = new Stroke(substrokes, strokeAttrs);
                allStrokes.Add(newStroke.XmlAttrs.Id, newStroke);
                strokes.Add(newStroke);
            }

            // Cycle through the Shape Id's pulled from the file
            foreach (KeyValuePair <Guid, XmlStructs.XmlShapeAttrs> shape in this.shapeToAttrs)
            {
                List <Substroke> substrokes = RecShape(shape.Key, allStrokes, allSubstrokes);

                // Add a new Shape
                Shape currShape = new Shape(substrokes, shape.Value);
                int   tag       = int.MinValue;
                if (this.shapeToTagNumber.ContainsKey(shape.Key))
                {
                    this.shapeToTagNumber.TryGetValue(shape.Key, out tag);
                }
                currShape.SubCircuitNumber = tag;
                shapes.Add(currShape);
                allShapes.Add(currShape.Id, currShape);
            }

            foreach (Shape s in shapes)
            {
                GetNeighbors(sketch, s, allShapes);
            }

            // Add the Shapes and Strokes to the Sketch
            sketch.AddStrokes(strokes);
            sketch.AddShapes(shapes);
            //Give the shapes the new tag numbers, so that viewing subcircuits works
            foreach (Sketch.Shape shape in Sketch.Shapes)
            {
                if (oldToNewTag.ContainsKey(shape.SubCircuitNumber))
                {
                    shape.SubCircuitNumber = oldToNewTag[shape.SubCircuitNumber];
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructs a sketch from the given stream
        /// </summary>
        /// <param name="reader">The XML reader that will read in XML data</param>
        private void CreateSketch(XmlTextReader reader)
        {
            // Read all the data from the XML file
            this.ReadSketchData(reader);

            ArrayList shapes  = new ArrayList();
            ArrayList strokes = new ArrayList();

            Hashtable allStrokes    = new Hashtable();
            Hashtable allSubstrokes = new Hashtable();

            // Cycle through the Stroke Id's pulled from the file
            foreach (DictionaryEntry stroke in this.strokeToSubstrokesHT)
            {
                ArrayList substrokes = new ArrayList();

                // Retrive the XML Stroke info (first element in the ArrayList)
                ArrayList substrokeIds = (ArrayList)stroke.Value;
                Sketch.XmlStructs.XmlShapeAttrs strokeAttrs = (Sketch.XmlStructs.XmlShapeAttrs)substrokeIds[0];

                // Cycle through the Substroke Id's pulled from the file
                for (int i = 1; i < substrokeIds.Count; i++)
                {
                    // Retrive the XML Substroke info and Points from the corresponding Hashtables
                    ArrayList ptsArray = (ArrayList)this.substrokeToPointsHT[(System.Guid)substrokeIds[i]];
                    ArrayList points   = new ArrayList();

                    Sketch.XmlStructs.XmlShapeAttrs substrokeAttrs = (Sketch.XmlStructs.XmlShapeAttrs)ptsArray[0];

                    // Get all of the Points associated with the Substroke
                    for (int k = 1; k < ptsArray.Count; k++)
                    {
                        points.Add((Point)pointsHT[(System.Guid)ptsArray[k]]);
                    }

                    // Create a new Substroke and add it to the local Hashtable and Stroke ArrayList
                    Substroke newSubstroke = new Substroke(points, substrokeAttrs);

                    allSubstrokes.Add((System.Guid)newSubstroke.XmlAttrs.Id, newSubstroke);
                    substrokes.Add(newSubstroke);
                }

                // Add a new Stroke
                Stroke newStroke = new Stroke(substrokes, strokeAttrs);
                allStrokes.Add(newStroke.XmlAttrs.Id, newStroke);
                strokes.Add(newStroke);
            }

            // Cycle through the Shape Id's pulled from the file
            foreach (DictionaryEntry shape in this.shapeToArgsHT)
            {
                ArrayList shapeValue = (ArrayList)shape.Value;

                // Retrive the XML Stroke info (first element in the ArrayList)
                Sketch.XmlStructs.XmlShapeAttrs shapeAttrs = (Sketch.XmlStructs.XmlShapeAttrs)shapeValue[0];

                ArrayList shapeIds   = (ArrayList)shapeValue[1];
                ArrayList currShapes = new ArrayList();

                ArrayList substrokes = RecShape((System.Guid)shape.Key, allStrokes, allSubstrokes, out currShapes);

                // Add a new Shape
                shapes.Add(new Shape(currShapes, substrokes, shapeAttrs));
            }

            // Add the Shapes and Strokes to the Sketch
            sketch.AddShapes(shapes);
            sketch.AddStrokes(strokes);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs a sketch from the given stream
        /// </summary>
        /// <param name="reader">The XML reader that will read in XML data</param>
        private void CreateSketch(XmlTextReader reader)
        {
            // Read all the data from the XML file
            this.ReadSketchData(reader);

            List <Shape>  shapes  = new List <Shape>();
            List <Stroke> strokes = new List <Stroke>();

            Dictionary <Guid, Stroke>    allStrokes    = new Dictionary <Guid, Stroke>();
            Dictionary <Guid, Substroke> allSubstrokes = new Dictionary <Guid, Substroke>();
            Dictionary <Guid, Shape>     allShapes     = new Dictionary <Guid, Shape>();

            // Cycle through the Stroke Id's pulled from the file

            foreach (KeyValuePair <Guid, XmlStructs.XmlShapeAttrs> stroke in this.strokeToAttrs)
            //foreach(KeyValuePair<Guid, ArrayList> stroke in this.strokeToSubstrokesHT)
            {
                XmlStructs.XmlShapeAttrs strokeAttrs = stroke.Value;
                List <Guid> substrokeIds             = this.strokeToSubstrokeIDs[stroke.Key];

                List <Substroke> substrokes = new List <Substroke>();

                // Cycle through the Substroke Id's pulled from the file
                int len = substrokeIds.Count;
                // Check if the file had no strokes.
                if (len == 0)
                {
                    Console.WriteLine("ERROR: File contains no strokes");
                }
                for (int i = 0; i < len; ++i)
                {
                    List <Guid> ptsArray = this.substrokeToPointIDs[substrokeIds[i]];
                    XmlStructs.XmlShapeAttrs substrokeAttrs = this.substrokeToAttrs[substrokeIds[i]];

                    List <Point> points = new List <Point>();

                    // Get all of the Points associated with the Substroke
                    int len2 = ptsArray.Count;
                    for (int k = 0; k < len2; ++k)
                    {
                        points.Add(this.pointsHT[ptsArray[k]]);
                    }

                    // Create a new Substroke and add it to the local Hashtable and Stroke ArrayList
                    Substroke newSubstroke = new Substroke(points, substrokeAttrs);

                    allSubstrokes.Add(newSubstroke.XmlAttrs.Id, newSubstroke);
                    substrokes.Add(newSubstroke);
                }

                // Add a new Stroke
                Stroke newStroke = new Stroke(substrokes, strokeAttrs);
                allStrokes.Add(newStroke.XmlAttrs.Id, newStroke);
                strokes.Add(newStroke);
            }

            // Cycle through the Shape Id's pulled from the file
            //foreach (KeyValuePair<Guid, ArrayList> shape in this.shapeToArgsHT)
            foreach (KeyValuePair <Guid, XmlStructs.XmlShapeAttrs> shape in this.shapeToAttrs)
            {
                /*
                 * XmlStructs.XmlShapeAttrs shapeAttrs = shape.Value;
                 *
                 * List<Shape> shapeIds = this.shapeToShapeIDs[shape.Key];
                 * List<Stroke> strokeIds = this.shapeToStrokeIDs[shape.Key];
                 * List<Substroke> substrokeIds = this.shapeToSubstrokeIDs[shape.Key];
                 */

                List <Substroke> substrokes = RecShape(shape.Key, allStrokes, allSubstrokes);

                // Add a new Shape
                Shape currShape = new Shape(substrokes, shape.Value);
                shapes.Add(currShape);
                allShapes.Add(currShape.Id, currShape);
            }
            foreach (Shape s in shapes)
            {
                GetNeighbors(sketch, s, allShapes);
            }

            // Add the Shapes and Strokes to the Sketch
            sketch.AddStrokes(strokes);
            sketch.AddShapes(shapes);
        }