Ejemplo n.º 1
0
        /// <summary>
        /// Returns true if this selector 'selects' the given object.
        /// </summary>
        /// <param name="zooms">The zooms selected.</param>
        /// <param name="mapCSSObject">The object to 'select'.</param>
        /// <returns></returns>
        public virtual bool Selects(MapCSSObject mapCSSObject, out KeyValuePair<int?, int?> zooms)
        {
            // store the zooms.
            if (this.Zoom == null)
            { // there are no zooms.
                zooms = new KeyValuePair<int?, int?>(
                    null, null);
            }
            else
            { // there are zooms.
                zooms = new KeyValuePair<int?, int?>(
                    this.Zoom.ZoomMin, this.Zoom.ZoomMax);
            }

            // check the type.
            switch (this.Type)
            {
                case SelectorTypeEnum.Area:
                    if (mapCSSObject.MapCSSType != MapCSSType.Area)
                    {
                        return false;
                    }
                    break;
                case SelectorTypeEnum.Canvas:
                    // no way the canvas can be here!
                    break;
                case SelectorTypeEnum.Line:
                    if (mapCSSObject.MapCSSType != MapCSSType.Line)
                    {
                        return false;
                    }
                    break;
                case SelectorTypeEnum.Node:
                    if (mapCSSObject.MapCSSType != MapCSSType.Node)
                    {
                        return false;
                    }
                    break;
                case SelectorTypeEnum.Way:
                    if (mapCSSObject.MapCSSType != MapCSSType.Way)
                    {
                        return false;
                    }
                    break;
                case SelectorTypeEnum.Relation:
                    if (mapCSSObject.MapCSSType != MapCSSType.Relation)
                    {
                        return false;
                    }
                    break;
            }

            // object is of correct type: check rule.
            if (this.SelectorRule != null &&
                !this.SelectorRule.Selects(mapCSSObject))
            { // oeps: the zoom was not valid.
                return false;
            }
            return true; // object is of correct and selected by rule.
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Evalues the value in this declaration or returns the regular value when there is no eval function.
 /// </summary>
 /// <param name="mapCSSObject">Map CSS object.</param>
 /// <returns></returns>
 public override float Eval(MapCSSObject mapCSSObject)
 {
     if (!string.IsNullOrWhiteSpace(this.EvalFunction))
     {
         return(EvalInterpreter.Instance.InterpretFloat(this.EvalFunction, mapCSSObject));
     }
     return(this.Value);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Evalues the value in this declaration or returns the regular value when there is no eval function.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 /// <param name="mapCSSObject">Map CSS object.</param>
 public override int Eval(MapCSSObject mapCSSObject)
 {
     if (!this.EvalFunction.IsNullOrWhiteSpace())
     {
         return(EvalInterpreter.Instance.InterpretInt(this.EvalFunction, mapCSSObject));
     }
     return(this.Value);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns true if this selector 'selects' the given object.
        /// </summary>
        /// <param name="zooms">The zooms selected.</param>
        /// <param name="mapCSSObject">The object to 'select'.</param>
        /// <returns></returns>
        public virtual bool Selects(MapCSSObject mapCSSObject, out SelectorZoom zooms)
        {
            // store the zooms.
            zooms = this.Zoom;

            // check the type.
            switch (this.Type)
            {
            case SelectorTypeEnum.Area:
                if (mapCSSObject.MapCSSType != MapCSSType.Area)
                {
                    return(false);
                }
                break;

            case SelectorTypeEnum.Canvas:
                // no way the canvas can be here!
                break;

            case SelectorTypeEnum.Line:
                if (mapCSSObject.MapCSSType != MapCSSType.Line)
                {
                    return(false);
                }
                break;

            case SelectorTypeEnum.Node:
                if (mapCSSObject.MapCSSType != MapCSSType.Node)
                {
                    return(false);
                }
                break;

            case SelectorTypeEnum.Way:
                if (mapCSSObject.MapCSSType != MapCSSType.Way)
                {
                    return(false);
                }
                break;

            case SelectorTypeEnum.Relation:
                if (mapCSSObject.MapCSSType != MapCSSType.Relation)
                {
                    return(false);
                }
                break;
            }

            // object is of correct type: check rule.
            if (this.SelectorRule != null &&
                !this.SelectorRule.Selects(mapCSSObject))
            { // oeps: the zoom was not valid.
                return(false);
            }
            return(true); // object is of correct and selected by rule.
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns true if the given object is selected by this selector rule.
        /// </summary>
        /// <param name="mapCSSObject"></param>
        /// <returns></returns>
        internal override bool Selects(MapCSSObject mapCSSObject)
        {
            string tagValue;

            if (mapCSSObject.TryGetValue(this.Tag, out tagValue))
            {
                double valueDouble;
                double tagValueDouble;
                switch (this.Comparator)
                {
                case SelectorRuleTagValueComparisonEnum.Equal:
                    return(tagValue == this.Value);

                case SelectorRuleTagValueComparisonEnum.NotEqual:
                    return(tagValue != this.Value);

                case SelectorRuleTagValueComparisonEnum.GreaterThan:
                    if (double.TryParse(this.Value, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out valueDouble) &&
                        (double.TryParse(tagValue, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tagValueDouble)))
                    {
                        return(tagValueDouble > valueDouble);
                    }
                    break;

                case SelectorRuleTagValueComparisonEnum.GreaterThanOrEqual:
                    if (double.TryParse(this.Value, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out valueDouble) &&
                        (double.TryParse(tagValue, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tagValueDouble)))
                    {
                        return(tagValueDouble >= valueDouble);
                    }
                    break;

                case SelectorRuleTagValueComparisonEnum.SmallerThan:
                    if (double.TryParse(this.Value, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out valueDouble) &&
                        (double.TryParse(tagValue, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tagValueDouble)))
                    {
                        return(tagValueDouble < valueDouble);
                    }
                    break;

                case SelectorRuleTagValueComparisonEnum.SmallerThanOrEqual:
                    if (double.TryParse(this.Value, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out valueDouble) &&
                        (double.TryParse(tagValue, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tagValueDouble)))
                    {
                        return(tagValueDouble <= valueDouble);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                return(mapCSSObject.ContainsKey(this.Tag));
            }
            return(false);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns true if the rule is to be applied to the given object.
 /// </summary>
 /// <param name="zooms"></param>
 /// <param name="mapCSSObject"></param>
 /// <returns></returns>
 public bool HasToBeAppliedTo(MapCSSObject mapCSSObject, out List <SelectorZoom> zooms)
 {
     zooms = new List <SelectorZoom>();
     foreach (var selector in this.Selectors)
     {
         SelectorZoom zoom;
         if (selector.Selects(mapCSSObject, out zoom))
         {
             zooms.Add(zoom);
         }
     }
     return(zooms.Count > 0);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Returns true if the rule is to be applied to the given object.
 /// </summary>
 /// <param name="zooms"></param>
 /// <param name="mapCSSObject"></param>
 /// <returns></returns>
 public bool HasToBeAppliedTo(MapCSSObject mapCSSObject, out List <KeyValuePair <int?, int?> > zooms)
 {
     zooms = new List <KeyValuePair <int?, int?> >();
     foreach (var selector in this.Selectors)
     {
         KeyValuePair <int?, int?> zoom;
         if (selector.Selects(mapCSSObject, out zoom))
         {
             zooms.Add(zoom);
         }
     }
     return(zooms.Count > 0);
 }
Ejemplo n.º 8
0
Archivo: Rule.cs Proyecto: JoeCooper/ui
 /// <summary>
 /// Returns true if the rule is to be applied to the given object.
 /// </summary>
 /// <param name="zooms"></param>
 /// <param name="mapCSSObject"></param>
 /// <returns></returns>
 public bool HasToBeAppliedTo(MapCSSObject mapCSSObject, out List<SelectorZoom> zooms)
 {
     zooms = new List<SelectorZoom>();
     foreach (var selector in this.Selectors)
     {
         SelectorZoom zoom;
         if (selector.Selects(mapCSSObject, out zoom))
         {
             zooms.Add(zoom);
         }
     }
     return zooms.Count > 0;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Returns true if the rule is to be applied to the given object.
 /// </summary>
 /// <param name="zooms"></param>
 /// <param name="mapCSSObject"></param>
 /// <returns></returns>
 public bool HasToBeAppliedTo(MapCSSObject mapCSSObject, out List<KeyValuePair<int?, int?>> zooms)
 {
     zooms = new List<KeyValuePair<int?, int?>>();
     foreach (var selector in this.Selectors)
     {
         KeyValuePair<int?, int?> zoom;
         if (selector.Selects(mapCSSObject, out zoom))
         {
             zooms.Add(zoom);
         }
     }
     return zooms.Count > 0;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns true if this selector 'selects' the given object.
        /// </summary>
        /// <param name="zooms">The zooms selected.</param>
        /// <param name="mapCSSObject">The object to 'select'.</param>
        /// <returns></returns>
        public virtual bool Selects(MapCSSObject mapCSSObject, out SelectorZoom zooms)
        {
            // store the zooms.
            zooms = this.Zoom;

            // check the type.
            switch (this.Type)
            {
                case SelectorTypeEnum.Area:
                    if (mapCSSObject.MapCSSType != MapCSSType.Area)
                    {
                        return false;
                    }
                    break;
                case SelectorTypeEnum.Canvas:
                    // no way the canvas can be here!
                    break;
                case SelectorTypeEnum.Line:
                    if (mapCSSObject.MapCSSType != MapCSSType.Line)
                    {
                        return false;
                    }
                    break;
                case SelectorTypeEnum.Node:
                    if (mapCSSObject.MapCSSType != MapCSSType.Node)
                    {
                        return false;
                    }
                    break;
                case SelectorTypeEnum.Way:
                    if (mapCSSObject.MapCSSType != MapCSSType.Way)
                    {
                        return false;
                    }
                    break;
                case SelectorTypeEnum.Relation:
                    if (mapCSSObject.MapCSSType != MapCSSType.Relation)
                    {
                        return false;
                    }
                    break;
            }

            // object is of correct type: check rule.
            if (this.SelectorRule != null &&
                !this.SelectorRule.Selects(mapCSSObject))
            { // oeps: the zoom was not valid.
                return false;
            }
            return true; // object is of correct and selected by rule.
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Returns true if the given object is selected by this selector rule.
        /// </summary>
        /// <param name="mapCSSObject"></param>
        /// <returns></returns>
        internal override bool Selects(MapCSSObject mapCSSObject)
        {
            switch (this.Operator)
            {
            case SelectorRuleOperator.And:
                return(this.Left.Selects(mapCSSObject) && this.Right.Selects(mapCSSObject));

            case SelectorRuleOperator.Or:
                return(this.Left.Selects(mapCSSObject) || this.Right.Selects(mapCSSObject));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Returns true if the given object is selected by this selector rule.
 /// </summary>
 /// <param name="mapCSSObject"></param>
 /// <returns></returns>
 internal abstract bool Selects(MapCSSObject mapCSSObject);
Ejemplo n.º 13
0
 /// <summary>
 /// Returns true if the given object is selected by this selector rule.
 /// </summary>
 /// <param name="mapCSSObject"></param>
 /// <returns></returns>
 internal override bool Selects(MapCSSObject mapCSSObject)
 {
     string tagValue;
     if (mapCSSObject.TryGetValue(this.Tag, out tagValue))
     {
         double valueDouble;
         double tagValueDouble;
         switch (this.Comparator)
         {
             case SelectorRuleTagValueComparisonEnum.Equal:
                 return tagValue == this.Value;
             case SelectorRuleTagValueComparisonEnum.NotEqual:
                 return tagValue != this.Value;
             case SelectorRuleTagValueComparisonEnum.GreaterThan:
                 if (double.TryParse(this.Value, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out valueDouble) &&
                     (double.TryParse(tagValue, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tagValueDouble)))
                 {
                     return tagValueDouble > valueDouble;
                 }
                 break;
             case SelectorRuleTagValueComparisonEnum.GreaterThanOrEqual:
                 if (double.TryParse(this.Value, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out valueDouble) &&
                     (double.TryParse(tagValue, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tagValueDouble)))
                 {
                     return tagValueDouble >= valueDouble;
                 }
                 break;
             case SelectorRuleTagValueComparisonEnum.SmallerThan:
                 if (double.TryParse(this.Value, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out valueDouble) &&
                     (double.TryParse(tagValue, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tagValueDouble)))
                 {
                     return tagValueDouble < valueDouble;
                 }
                 break;
             case SelectorRuleTagValueComparisonEnum.SmallerThanOrEqual:
                 if (double.TryParse(this.Value, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out valueDouble) &&
                     (double.TryParse(tagValue, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tagValueDouble)))
                 {
                     return tagValueDouble <= valueDouble;
                 }
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
         return mapCSSObject.ContainsKey(this.Tag);
     }
     return false;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Returns true if the given object is selected by this selector rule.
 /// </summary>
 /// <param name="mapCSSObject"></param>
 /// <returns></returns>
 internal override bool Selects(MapCSSObject mapCSSObject)
 {
     return mapCSSObject.ContainsKey(this.Tag);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Returns true if the given object is selected by this selector rule.
 /// </summary>
 /// <param name="mapCSSObject"></param>
 /// <returns></returns>
 internal override bool Selects(MapCSSObject mapCSSObject)
 {
     switch (this.Operator)
     {
         case SelectorRuleOperator.And:
             return this.Left.Selects(mapCSSObject) && this.Right.Selects(mapCSSObject);
         case SelectorRuleOperator.Or:
             return this.Left.Selects(mapCSSObject) || this.Right.Selects(mapCSSObject);
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Returns true if this selector 'selects' the given object.
        /// </summary>
        /// <param name="zooms">The zooms selected.</param>
        /// <param name="mapCSSObject">The object to 'select'.</param>
        /// <returns></returns>
        public virtual bool Selects(MapCSSObject mapCSSObject, out KeyValuePair <int?, int?> zooms)
        {
            // store the zooms.
            if (this.Zoom == null)
            { // there are no zooms.
                zooms = new KeyValuePair <int?, int?>(
                    null, null);
            }
            else
            { // there are zooms.
                zooms = new KeyValuePair <int?, int?>(
                    this.Zoom.ZoomMin, this.Zoom.ZoomMax);
            }

            // check the type.
            switch (this.Type)
            {
            case SelectorTypeEnum.Area:
                if (mapCSSObject.MapCSSType != MapCSSType.Area)
                {
                    return(false);
                }
                break;

            case SelectorTypeEnum.Canvas:
                // no way the canvas can be here!
                break;

            case SelectorTypeEnum.Line:
                if (mapCSSObject.MapCSSType != MapCSSType.Line)
                {
                    return(false);
                }
                break;

            case SelectorTypeEnum.Node:
                if (mapCSSObject.MapCSSType != MapCSSType.Node)
                {
                    return(false);
                }
                break;

            case SelectorTypeEnum.Way:
                if (mapCSSObject.MapCSSType != MapCSSType.Way)
                {
                    return(false);
                }
                break;

            case SelectorTypeEnum.Relation:
                if (mapCSSObject.MapCSSType != MapCSSType.Relation)
                {
                    return(false);
                }
                break;
            }

            // object is of correct type: check rule.
            if (this.SelectorRule != null &&
                !this.SelectorRule.Selects(mapCSSObject))
            { // oeps: the zoom was not valid.
                return(false);
            }
            return(true); // object is of correct and selected by rule.
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Returns true if the given object is selected by this selector rule.
 /// </summary>
 /// <param name="mapCSSObject"></param>
 /// <returns></returns>
 internal abstract bool Selects(MapCSSObject mapCSSObject);
Ejemplo n.º 18
0
 /// <summary>
 /// Returns true if the given object is selected by this selector rule.
 /// </summary>
 /// <param name="mapCSSObject"></param>
 /// <returns></returns>
 internal override bool Selects(MapCSSObject mapCSSObject)
 {
     return(mapCSSObject.ContainsKey(this.Tag));
 }