public CartoSelector(IEnumerable<Element> elements, Env env)
      : base(elements)
    {
      m_filters = new CartoFilterSet();
      m_zooms = new NodeList<CartoZoomElement>();
      m_elements = new NodeList<CartoElement>();

      m_conditions = 0;
      if (env == null)
      	env = new Env(); // TODO
      
      foreach (Element elem in elements)
      {
        if (elem is CartoFilterElement)
        {
          m_filters.Add(elem as CartoFilterElement, env);
          m_conditions++;
        }
        else if (elem is CartoZoomElement)
        {
          m_zooms.Add(elem as CartoZoomElement);
          m_conditions++;
        }
        else if (elem is CartoAttachmentElement)
          m_attachment = (elem as CartoAttachmentElement).Value;
        else
          m_elements.Add((CartoElement)elem);
      }
    }
    public bool CanCloneWith(CartoFilterSet other, Env env)
    {
      int additions = 0;

      if (m_filters.Count > 0)
      {
        foreach (KeyValuePair<string, CartoFilterElement> kv in other.m_filters)
        {
          string id = kv.Key;
          object status = this.Addable(kv.Value, env);
          if (status != null)
          {
            if ((bool)status == false)
            {
              return true;
            }
            if ((bool)status == true)
            {
              additions++;
            }
          }
        }
      }
      else
      {
        additions += other.m_filters.Count;
      }

      return additions > 0;
    }
Example #3
0
        public CartoSelector(IEnumerable <Element> elements, Env env)
            : base(elements)
        {
            m_filters  = new CartoFilterSet();
            m_zooms    = new NodeList <CartoZoomElement>();
            m_elements = new NodeList <CartoElement>();

            m_conditions = 0;
            if (env == null)
            {
                env = new Env(); // TODO
            }
            foreach (Element elem in elements)
            {
                if (elem is CartoFilterElement)
                {
                    m_filters.Add(elem as CartoFilterElement, env);
                    m_conditions++;
                }
                else if (elem is CartoZoomElement)
                {
                    m_zooms.Add(elem as CartoZoomElement);
                    m_conditions++;
                }
                else if (elem is CartoAttachmentElement)
                {
                    m_attachment = (elem as CartoAttachmentElement).Value;
                }
                else
                {
                    m_elements.Add((CartoElement)elem);
                }
            }
        }
        public bool CanCloneWith(CartoFilterSet other, Env env)
        {
            int additions = 0;

            if (m_filters.Count > 0)
            {
                foreach (KeyValuePair <string, CartoFilterElement> kv in other.m_filters)
                {
                    string id     = kv.Key;
                    object status = this.Addable(kv.Value, env);
                    if (status != null)
                    {
                        if ((bool)status == false)
                        {
                            return(true);
                        }
                        if ((bool)status == true)
                        {
                            additions++;
                        }
                    }
                }
            }
            else
            {
                additions += other.m_filters.Count;
            }

            return(additions > 0);
        }
Example #5
0
 public CartoDefinition(CartoDefinition def, CartoFilterSet filters, Env env)
 {
     m_rules       = CreateCopy(def.Rules);
     m_elements    = new NodeList <CartoElement>(def.m_elements);
     m_ruleIndex   = new List <string>(def.m_ruleIndex);
     m_filters     = filters != null ? filters : (CartoFilterSet)def.Filters.Clone(env);
     m_attachment  = def.Attachment;
     m_zoom        = def.m_zoom;
     m_specificity = def.m_specificity;
 }
 public CartoDefinition(CartoDefinition def, CartoFilterSet filters, Env env)
 {
   m_rules = CreateCopy(def.Rules);
   m_elements = new NodeList<CartoElement>(def.m_elements);
   m_ruleIndex = new List<string>(def.m_ruleIndex);
   m_filters = filters != null ? filters : (CartoFilterSet)def.Filters.Clone(env);
   m_attachment = def.Attachment;
   m_zoom = def.m_zoom;
   m_specificity = def.m_specificity;
 }
Example #7
0
        public CartoSelector(CartoSelector selector)
            : base(selector.ElementsInternal)
        {
            m_zooms      = new NodeList <CartoZoomElement>();
            m_elements   = new NodeList <CartoElement>();
            m_filters    = new CartoFilterSet();
            m_attachment = selector.Attachment;
            m_zoom       = selector.Zoom;
            m_index      = selector.m_index;

            Location = selector.Location;
        }
    public CartoSelector(CartoSelector selector)
      : base(selector.ElementsInternal)
    {
      m_zooms = new NodeList<CartoZoomElement>();
      m_elements = new NodeList<CartoElement>();
      m_filters = new CartoFilterSet();
      m_attachment = selector.Attachment;
      m_zoom = selector.Zoom;
      m_index = selector.m_index;

      Location = selector.Location;
    }
    public CartoDefinition(CartoSelector selector, CartoRule[] rules)
    {
      m_rules = new NodeList<CartoRule>();
      m_elements = selector.Elements;
      m_filters = selector.Filters;
      m_rules.AddRange(rules);
      m_zoom = selector.Zoom;
      m_attachment = selector.Attachment ?? "__default__";
      m_ruleIndex = new List<string>();
      for (int i = 0; i < m_rules.Count; i++)
      {
        m_rules[i].Zoom = selector.Zoom;
        m_ruleIndex.Add(m_rules[i].Id);
      }

      m_specificity = selector.Specificity();
    }
Example #10
0
        public CartoDefinition(CartoSelector selector, CartoRule[] rules)
        {
            m_rules    = new NodeList <CartoRule>();
            m_elements = selector.Elements;
            m_filters  = selector.Filters;
            m_rules.AddRange(rules);
            m_zoom       = selector.Zoom;
            m_attachment = selector.Attachment ?? "__default__";
            m_ruleIndex  = new List <string>();
            for (int i = 0; i < m_rules.Count; i++)
            {
                m_rules[i].Zoom = selector.Zoom;
                m_ruleIndex.Add(m_rules[i].Id);
            }

            m_specificity = selector.Specificity();
        }
    public static string ToFilter(CartoFilterSet filterSet, CartoReaderContext cntx)
    {
      string result = string.Empty;

      if (filterSet.Count > 0)
      {
        int i = 0;
        foreach (CartoFilterElement filter in filterSet.Filters)
        {
          if (i != 0)
            result += " and ";

          result += cntx.Translator.ToFilter(cntx.GetValue( filter.Key), ToExpressionOperator(filter.Op), ToExpressionValue(filter.Value, cntx));
          i++;
        }
      }

      return result;
    }
    public static string ToFilter(CartoFilterSet filterSet, ICartoTranslator cartoTranslator)
    {
      string result = string.Empty;

      if (filterSet.Count > 0)
      {
        int i = 0;
        foreach (CartoFilterElement filter in filterSet.Filters)
        {
          if (i != 0)
            result += " and ";

          result += cartoTranslator.ToFilter(filter.Key.ToString(), ToExpressionOperator(filter.Op), ToExpressionValue(filter.Value));
          i++;
        }
      }

      return result;
    }
    public object CloneWith(CartoFilterSet other, Env env)
    {
      List<CartoFilterElement> additions = null;

      if (m_filters.Count > 0)
      {
        foreach (KeyValuePair<string, CartoFilterElement> kv in other.m_filters)
        {
          string id = kv.Key;
          object status = this.Addable(kv.Value, env);
          if (status != null)
          {
            if ((bool)status == false)
            {
              return false;
            }
            if ((bool)status == true)
            {
              // Adding the filter will override another value.
              if (additions == null)
                additions = new List<CartoFilterElement>();
              additions.Add(other.m_filters[id]);
            }
          }
        }
      }
      else
      {
        if (other.m_filters.Count > 0)
        {
          additions = new List<CartoFilterElement>(other.m_filters.Count);
          foreach (KeyValuePair<string, CartoFilterElement> kv in other.m_filters)
            additions.Add(other.m_filters[kv.Key]);
        }
      }

      // Adding the other filters doesn't make this filterset invalid, but it
      // doesn't add anything to it either.
      if (additions == null) return null;

      // We can successfully add all filters. Now clone the filterset and add the
      // new rules.
      var clone = new CartoFilterSet();

      // We can add the rules that are already present without going through the
      // add function as a Filterset is always in it's simplest canonical form.
      foreach (KeyValuePair<string, CartoFilterElement> kv1 in m_filters)
      {
      	  CartoFilterElement filter = kv1.Value;
      	  clone.m_filters[kv1.Key] = filter;
      }

      // Only add new filters that actually change the filter.
      //while (id = additions.shift()) {
      foreach (CartoFilterElement id in additions)
      {
      	clone.Add(id, env);
      }

      return clone;
    }
        public object Clone(Env env)
        {
            var clone = new CartoFilterSet(m_filters, env);

            return(clone);
        }
        public object CloneWith(CartoFilterSet other, Env env)
        {
            List <CartoFilterElement> additions = null;

            if (m_filters.Count > 0)
            {
                foreach (KeyValuePair <string, CartoFilterElement> kv in other.m_filters)
                {
                    string id     = kv.Key;
                    object status = this.Addable(kv.Value, env);
                    if (status != null)
                    {
                        if ((bool)status == false)
                        {
                            return(false);
                        }
                        if ((bool)status == true)
                        {
                            // Adding the filter will override another value.
                            if (additions == null)
                            {
                                additions = new List <CartoFilterElement>();
                            }
                            additions.Add(other.m_filters[id]);
                        }
                    }
                }
            }
            else
            {
                if (other.m_filters.Count > 0)
                {
                    additions = new List <CartoFilterElement>(other.m_filters.Count);
                    foreach (KeyValuePair <string, CartoFilterElement> kv in other.m_filters)
                    {
                        additions.Add(other.m_filters[kv.Key]);
                    }
                }
            }

            // Adding the other filters doesn't make this filterset invalid, but it
            // doesn't add anything to it either.
            if (additions == null)
            {
                return(null);
            }

            // We can successfully add all filters. Now clone the filterset and add the
            // new rules.
            var clone = new CartoFilterSet();

            // We can add the rules that are already present without going through the
            // add function as a Filterset is always in it's simplest canonical form.
            foreach (KeyValuePair <string, CartoFilterElement> kv1 in m_filters)
            {
                CartoFilterElement filter = kv1.Value;
                clone.m_filters[kv1.Key] = filter;
            }

            // Only add new filters that actually change the filter.
            //while (id = additions.shift()) {
            foreach (CartoFilterElement id in additions)
            {
                clone.Add(id, env);
            }

            return(clone);
        }
Example #16
0
        public object Clone(CartoFilterSet filters, Env env)
        {
            CartoDefinition clone = new CartoDefinition(this, filters, env);

            return(clone);
        }
 public object Clone(Env env)
 {
   var clone = new CartoFilterSet(m_filters, env);
   return clone;
 }
 public object Clone(CartoFilterSet filters, Env env)
 {
   CartoDefinition clone = new CartoDefinition(this, filters, env);
   return clone;
 }