예제 #1
0
        /* This is where the SVG file elements get loaded into Cookie Cutter Control Software.
         * After being processed with attributes, the elements are converted into an SVGelement
         * array. Then Processor.shortPath returns the shortest possible distance between all the
         * SVGelements, which is stored into memory while being sent over in one instruction at a
         * time to the Cookie Cutter. On the client side, the Arduino waits to get a go command,
         * after which, it moves along a path given to it by this program. Once the servo motors
         * move to the desired location, the client sends a completed signal back to the control
         * software. This process is repeated until all the SVGelements have been cut out. */
        public static SVGElementArray getElements(string URL)
        {
            SVGElementArray allElements = new SVGElementArray();

            /* process elements by getting their attribute values and
            *  running their attributes though their appropriate void */

            allElements = Quadify.path(URL);

            /* Quadify path converts a path's d's and poinits into SVGelements.
             *  It supports lines, ellipses, arcto's, cubic, & quadradic curves */

            copyOver(Quadify.rect(URL), ref allElements);

            /* Quadify rect takes the rectangle transforms and combines the rectangles into
             * one matrix and then creates SVGlines based on their deminsional attributes */

            copyOver(Quadify.line(URL), ref allElements);

            /* Quadify line takes the x1, y1, x2, & y2 values of an XML SVG line and after
             * mulitplying out the matricies, creates a new SVGline */

            copyOver(Quadify.polygon(URL), ref allElements);
            copyOver(Quadify.polyline(URL), ref allElements);

            /* Polygon and polyline take in a series of points from polyline
             * or polygon element and process them into an SVGElement array */

            copyOver(Quadify.circle(URL), ref allElements);
            copyOver(Quadify.ellipse(URL), ref allElements);

            /* Quadify circle and polygon are relativly simple; These functions parse the
             * radius and center locations of an ellipse or circle to make an SVGellise*/

            allElements = Processer.shortPath(allElements);
            /* Processor.shortPath finds the shortest possible path connecting all the elements */
            return(allElements);
        }
예제 #2
0
        public static SVGElementArray path(attributeArray attributeValues)
        {
            //0 = d's : 1 = points
            //takes in d and points to make an SVGElementArray

            //!!ADD SUPPORT FOR POINTS TO POLYLINE CONVERSION!!

            SVGElementArray returnElements = new SVGElementArray();
            List <char>     allCMD         = new List <char>();

            //transforming
            string[] matricies     = new string[0];
            int      numTransforms = attributeValues.atributes.Count
                                     - allElementAttributes.path.Count();

            //seporate the transform matricies from the other attributes
            for (int transformNum = 0; transformNum < numTransforms; transformNum++)
            {
                Array.Resize(ref matricies, matricies.Length + 1);
                matricies[transformNum] = attributeValues.atributes
                                          [allElementAttributes.path.Count() + transformNum];
            }
            transformMatrix finalMatrix = transform.combineMatricies(matricies);
            string          dVal        = attributeValues.atributes[0];

            string[] seporateDVals = dVal.Split(new char[2] {
                ' ', ','
            });
            char         CMD           = ' ';
            point        handle0       = new point();
            point        handle1       = new point();
            point        startPoint    = new point();
            point        currentPoint  = new point();
            point        previousPoint = new point();
            QuadCode     quadCode      = new QuadCode();
            List <point> moveTos       = new List <point>();

            //going through the loop
            for (int dValIndex = 0; dValIndex < seporateDVals.Length - 1; dValIndex++)
            {
                //look for a cmd
                char firstChar = seporateDVals[dValIndex][0];
                if (char.IsLetter(firstChar) == true)
                {
                    CMD = firstChar;
                    if (seporateDVals[dValIndex].Length > 1)
                    {
                        seporateDVals[dValIndex] = seporateDVals[dValIndex].Substring(1);
                    }
                    else
                    {
                        dValIndex++;
                    }
                    allCMD.Add(CMD);
                }
                double firstVal = double.Parse(seporateDVals[dValIndex]);
                switch (CMD)
                {
                case 'M':     //move to point absolute
                    startPoint.x = firstVal;
                    dValIndex++;
                    startPoint.y = double.Parse(seporateDVals[dValIndex]);
                    currentPoint = startPoint;
                    moveTos.Add(startPoint);
                    break;

                case 'm':     //move to point relative
                    startPoint.x = currentPoint.x + firstVal;
                    dValIndex++;
                    startPoint.y = currentPoint.y + double.Parse(seporateDVals[dValIndex]);
                    currentPoint = startPoint;
                    moveTos.Add(startPoint);
                    break;

                case 'L':     //line to point absolute
                    currentPoint.x = firstVal;
                    dValIndex++;
                    currentPoint.y = double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'l':     //line to point relative
                    currentPoint.x += firstVal;
                    dValIndex++;
                    currentPoint.y += double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'H':     //horizontal line absolute
                    currentPoint.x = firstVal;
                    currentPoint.y = 0;
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'h':     //horizontal line relative
                    currentPoint.x += firstVal;
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'V':     //vertical line absolute
                    currentPoint.x = 0;
                    currentPoint.y = firstVal;
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'v':     //vertical line relative
                    currentPoint.y += firstVal;
                    returnElements.SVGelement.Add(quadCode.addLine(previousPoint, currentPoint, matricies));
                    break;

                case 'C':     // Cubic bezier curve absolute
                case 'S':
                    handle0.x = firstVal;
                    dValIndex++;
                    handle0.y = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    handle1.x = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    handle1.y = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.x = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.y = double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle1, currentPoint, matricies));
                    break;

                case 'c':     // Cubic bezier curve relative
                case 's':
                    handle0.x = previousPoint.x + firstVal;
                    dValIndex++;
                    handle0.y = previousPoint.y + double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    handle1.x = previousPoint.x + double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    handle1.y = previousPoint.y + double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.x += double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.y += double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle1, currentPoint, matricies));
                    break;

                case 'Q':     // Cubic bezier curve absolute
                case 'T':
                    handle0.x = firstVal;
                    dValIndex++;
                    handle0.y = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.x = double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.y = double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle0, currentPoint, matricies));
                    break;

                case 'q':     // Cubic bezier curve relative
                case 't':
                    handle0.x = previousPoint.x + firstVal;
                    dValIndex++;
                    handle0.y = previousPoint.y + double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.x += double.Parse(seporateDVals[dValIndex]);
                    dValIndex++;
                    currentPoint.y += double.Parse(seporateDVals[dValIndex]);
                    returnElements.SVGelement.Add(quadCode.addCurve(previousPoint, handle0, handle0, currentPoint, matricies));
                    break;

                case 'A':     //Arcto absolute
                    //????????????????????
                    break;

                case 'a':     //Arcto relative
                    //????????????????????
                    break;

                case 'Z':     //closing line to start point
                case 'z':
                    returnElements.SVGelement.Add(quadCode.addLine(startPoint, currentPoint, matricies));
                    break;
                }
                previousPoint = currentPoint;
            }
            if (allCMD.Count == 2)
            {
                if (allCMD[0].ToString().ToUpper() == "M" & allCMD[1].ToString().ToUpper() == "Z")
                {
                    return(Quadify.polylineToQuadLine(moveTos.ToArray(), matricies, true));
                }
            }
            else if (allCMD.Count == 1)
            {
                if (allCMD[0].ToString().ToUpper() == "M")
                {
                    return(Quadify.polylineToQuadLine(moveTos.ToArray(), matricies, true));
                }
            }
            return(returnElements);
        }