Beispiel #1
0
        /// <summary>
        /// Build a string that represents a HPGL polyline.
        /// </summary>
        /// <param name="serialisedToken">The token to utilised</param>
        private string PolygonCommand(SerialiseObject serialisedToken)
        {
            StringBuilder builder         = new StringBuilder();
            Dictionary <string, string> s = serialisedToken.attributes;
            string val;

            s.TryGetValue("path", out val);
            // Split all the coordinates in the path string.
            string[] points = val.Split(' ').ToArray();

            // Split the X and Y value from the first coordinate.
            string[] initialpoint = points[0].Split(',');
            (string initx, string inity) = (initialpoint[0], initialpoint[1]);

            // Append the first line.
            builder.AppendLine($"PU {initx},{inity};");

            string[] pair;

            for (int i = 1; i < points.Length; i++)
            {
                // Split each coordinate string into its numbers.
                pair = points[i].Split(',');
                builder.AppendLine($"PD {pair[0]},{pair[1]};");
            }

            // Close the polygon.
            builder.AppendLine($"PD {initx},{inity};\n" +
                               $"PU;");

            return(builder.ToString());
        }
        /// <summary>
        /// Serialise a single token.
        /// </summary>
        /// <param name="token"></param>
        public static void Parse(IToken token)
        {
            SerialiseObject wrapper = new SerialiseObject();

            JsonSerializerOptions options = new JsonSerializerOptions
            {
                WriteIndented = true
            };

            var Json = JsonSerializer.Serialize(wrapper, options) + "\n";

            IRWriter.Write(Json, @path);
        }
Beispiel #3
0
        /// <summary>
        /// Build a string that represents a HPGL circle.
        /// </summary>
        /// <param name="serialisedToken"> The token to utilise. </param>
        private string CircleCommand(SerialiseObject serialisedToken)
        {
            Dictionary <string, string> keys = serialisedToken.attributes;
            string x, y, r;

            keys.TryGetValue("x", out x);
            keys.TryGetValue("y", out y);
            keys.TryGetValue("r", out r);

            string cmd = $"PU {x},{y};\n" +
                         $"CI{r},{resolution};";

            return(cmd);
        }
Beispiel #4
0
        /// <summary>
        /// Build a string that represents a HPGL line.
        /// </summary>
        /// <param name="serialisedToken"> The token to utilise. </param>
        private string LineCommand(SerialiseObject serialisedToken)
        {
            Dictionary <string, string> s = serialisedToken.attributes;
            string x1, y1, x2, y2;

            s.TryGetValue("x1", out x1);
            s.TryGetValue("y1", out y1);
            s.TryGetValue("x2", out x2);
            s.TryGetValue("y2", out y2);

            string cmd = $"PU {x1},{y1};\n" +
                         $"PD {x2},{y2};\n" +
                         $"PU;";

            return(cmd);
        }
Beispiel #5
0
        /// <summary>
        /// Build a string that represents a HPGL rectangle.
        /// </summary>
        /// <param name="serialisedToken"> The token to utilise. </param>
        private string RectangleCommand(SerialiseObject serialisedToken)
        {
            Dictionary <string, string> keys = serialisedToken.attributes;
            string x, y, width, height;

            keys.TryGetValue("x", out x);
            keys.TryGetValue("y", out y);
            keys.TryGetValue("width", out width);
            keys.TryGetValue("height", out height);

            string cmd = $"PU {x},{y};\n" +
                         $"ER {width},{height};\n" +
                         $"PU;";

            return(cmd);
        }
        /// <summary>
        /// Parse a given array of tokens.
        /// </summary>
        /// <param name="tokens">The tokens to be parsed.</param>
        public static void Parse(IToken[] tokens)
        {
            JsonRoot        jsonRoot;
            SerialiseObject serialiseObject;

            // Set the Json intentation option to true.
            JsonSerializerOptions options = new JsonSerializerOptions
            {
                WriteIndented = true
            };

            // Instansiate a jsonroot object and set its internal array of tokens
            // to the number of tokens passed to it.
            jsonRoot            = new JsonRoot();
            jsonRoot.tokenarray = new SerialiseObject[tokens.Length];

            // For each token.
            for (int i = 0; i < tokens.Length; i++)
            {
                // If it is not null
                if (tokens[i] != null)
                {
                    // Set the serialiseObject to the values stored in the token.
                    IToken token = tokens[i];
                    serialiseObject            = new SerialiseObject();
                    serialiseObject.tokenID    = token.GetID();
                    serialiseObject.attributes = token.GetNamedParameters();

                    // Style information goes here...

                    // Add the serialiseObject representation of the token to the JsonRoot object.
                    jsonRoot.tokenarray[i] = serialiseObject;
                }
            }

            // Serialise the JsonRoot object and write it.
            var Json = JsonSerializer.Serialize <JsonRoot>(jsonRoot, options);

            IRWriter.Write(Json, @path);
        }
Beispiel #7
0
 /// <summary>
 /// Build a string that represents a HPGL ellipse.
 /// </summary>
 /// <param name="serialisedToken"> The token to utilise. </param>
 private string EllipseCommand(SerialiseObject serialiseToken)
 {
     // Not implemented but fails silently.
     return(null);
 }