/// <summary> /// This method returns a list of Criteria /// </summary> public static List <PixelCriteria> ParseCriteria(string queryText, ActionTypeEnum actionType) { // initial value List <PixelCriteria> criteria = null; // locals int count = 0; string text = ""; PixelCriteria pixelCriteria = null; // If the queryText string exists if (TextHelper.Exists(queryText)) { // Get the lines of text List <TextLine> lines = WordParser.GetTextLines(queryText); // If the lines collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(lines)) { // Create a new collection of 'PixelCriteria' objects. criteria = new List <PixelCriteria>(); // parse the text lines foreach (TextLine textLine in lines) { // Increment the value for count count++; // Get the text text = textLine.Text.ToLower(); // verify the line has text in case the user hit enter at the end of the line if (TextHelper.Exists(text)) { // if this is DrawLine if (actionType == ActionTypeEnum.DrawLine) { // if this is the first line if (count == 1) { // Create the pixelCriteria based upon this text pixelCriteria = CreatePixelCriteria(text, actionType, count); // verify the pixelCriteria exists before adding if (pixelCriteria != null) { // Add this criteria criteria.Add(pixelCriteria); } } else if (count == 2) { // Set the ComparisonText SetComparisonType(text, ref pixelCriteria); } else { // Create the pixelCriteria based upon this text pixelCriteria = CreatePixelCriteria(text, actionType, count, pixelCriteria); } } else { // Create the pixelCriteria based upon this text pixelCriteria = CreatePixelCriteria(text, actionType, count); // verify the pixelCriteria exists before adding if (pixelCriteria != null) { // Set the ComparisonText SetComparisonType(text, ref pixelCriteria); // Add this criteria criteria.Add(pixelCriteria); } } } } } } // return value return(criteria); }
/// <summary> /// This method returns the Comparison Type /// </summary> public static ComparisonTypeEnum SetComparisonType(string text, ref PixelCriteria pixelCriteria) { // initial value ComparisonTypeEnum comparisonType = ComparisonTypeEnum.Unknown; // locals int number1 = -1000; int number2 = -1000; int number3 = -1000; int number4 = -1000; // if the text exists if ((TextHelper.Exists(text)) && (NullHelper.Exists(pixelCriteria))) { // drawing is different for DrawLine if (pixelCriteria.PixelType == PixelTypeEnum.DrawLine) { // Parse out the numbers from the text ParseNumbers(text, ref number1, ref number2, ref number3, ref number4); // Set the Start and End Point pixelCriteria.StartPoint = new Point(number1, number2); pixelCriteria.EndPoint = new Point(number3, number4); } else { // Parse out the numbers from the text ParseNumbers(text, ref number1, ref number2); // if the text contains less than if (text.Contains("<")) { // Set to Less Than comparisonType = ComparisonTypeEnum.LessThan; // Set the MaxValue pixelCriteria.MaxValue = number1; } // if the text contains between else if (text.Contains("between")) { // Set to Between comparisonType = ComparisonTypeEnum.Between; // Set the MinValue pixelCriteria.MinValue = number1; // Set the MaxValue pixelCriteria.MaxValue = number2; } // if the text contains greater than else if (text.Contains(">")) { // Set to Greater Than comparisonType = ComparisonTypeEnum.GreaterThan; // Set the MinValue pixelCriteria.MinValue = number1; } else if (text.Contains("=")) { // Set to Equals comparisonType = ComparisonTypeEnum.Equals; // Set the TargetValue pixelCriteria.TargetValue = number1; } } // set the comparisonType on the object passed in pixelCriteria.ComparisonType = comparisonType; } // return value return(comparisonType); }
/// <summary> /// This method returns the Pixel Criteria /// </summary> public static PixelCriteria CreatePixelCriteria(string text, ActionTypeEnum actionType, int lineNumber, PixelCriteria existingCriteria = null) { // initial value PixelCriteria pixelCriteria = null; // only use a space as a delimiter character char[] delimiterChars = { ' ' }; // If the text string exists if (TextHelper.Exists(text)) { // Set the BackColor if (actionType == ActionTypeEnum.SetBackColor) { // Create a new instance of a 'PixelCriteria' object. pixelCriteria = new PixelCriteria(); // Get the words List <Word> words = WordParser.GetWords(text, delimiterChars); // If the words collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(words)) { // if there are 3 words if (words.Count == 3) { // if the third word is null if (words[2].Text.ToLower() == "null") { // Set the value for the property 'RemoveBackColor' to true pixelCriteria.RemoveBackColor = true; } else { // Set the BackColor pixelCriteria.BackColor = Color.FromName(words[2].Text); } } else if (words.Count == 5) { // set the value for Red, Green & Blue int red = NumericHelper.ParseInteger(words[2].Text, -1, -1); int green = NumericHelper.ParseInteger(words[3].Text, -1, -1); int blue = NumericHelper.ParseInteger(words[4].Text, -1, -1); // if all the RGB values are set if ((red >= 0) && (green >= 0) && (blue >= 0)) { // Set the BackColor pixelCriteria.BackColor = Color.FromArgb(red, green, blue); } } } } // if this is a draw line else if (actionType == ActionTypeEnum.DrawLine) { // if the existingCriteria if (NullHelper.IsNull(existingCriteria)) { // Create a new instance of a 'PixelCriteria' object. pixelCriteria = new PixelCriteria(); } else { // use the existing criteria so more properties can be set on it pixelCriteria = existingCriteria; } // Set to DrawLine pixelCriteria.PixelType = PixelTypeEnum.DrawLine; // if this is the first line if (lineNumber == 1) { // Get the words List <Word> words = WordParser.GetWords(text, delimiterChars); // If the words collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(words)) { // Get the lastWord Word lastWord = words[words.Count - 1]; // Set the thickness pixelCriteria.Thickness = NumericHelper.ParseInteger(lastWord.Text, -1000, -1001); } } else if (lineNumber == 3) { // Set the RepeatType and the repeating attributes pixelCriteria.RepeatType = SetRepeatType(text); // if the repeat type was found if (pixelCriteria.RepeatType != RepeatTypeEnum.NoRepeat) { // get the text after the repeat string repeatText = GetRepeatText(text, pixelCriteria.RepeatType); // get the words List <Word> words = WordParser.GetWords(repeatText); // if there are exactly two words if ((ListHelper.HasOneOrMoreItems(words)) && (words.Count == 2)) { // set the repititions pixelCriteria.Repititions = NumericHelper.ParseInteger(words[0].Text, 0, -1); // set the Distance pixelCriteria.Distance = NumericHelper.ParseInteger(words[1].Text, 0, -1); } } } } else if (lineNumber > 1) { // Create a new instance of a 'PixelCriteria' object. pixelCriteria = new PixelCriteria(); // if this text contains bluegreen if (text.Contains("x")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.X; } else if (text.Contains("y")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.Y; } else if (text.Contains("bluegreen")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.BlueGreen; } // if this text contains bluegreen else if (text.Contains("bluered")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.BlueRed; } // if this text contains bluegreen else if (text.Contains("greenred")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.GreenRed; } else if (text.Contains("red")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.Red; } else if (text.Contains("green")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.Green; } else if (text.Contains("blue")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.Blue; } else if (text.Contains("total")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.Total; } } } // return value return(pixelCriteria); }