private void AddRuleButton_Click(object sender, EventArgs e) { if (m_point != null) { IPointRule prt = _factory.CreateDefaultPointRule(); int idx = m_point.RuleCount; conditionList.AddRuleControl(prt, idx).Focus(); m_point.AddRule(prt); } else if (m_line != null) { ILineRule lrt = _factory.CreateDefaultLineRule(); int idx = m_line.RuleCount; conditionList.AddRuleControl(lrt, idx).Focus(); m_line.AddRule(lrt); } else if (m_area != null) { IAreaRule art = _factory.CreateDefaultAreaRule(); int idx = m_area.RuleCount; conditionList.AddRuleControl(art, idx).Focus(); m_area.AddRule(art); } else if (m_comp != null) { ICompositeRule cr = _factory.CreateDefaultCompositeRule(); int idx = m_area.RuleCount; conditionList.AddRuleControl(cr, idx).Focus(); m_comp.AddCompositeRule(cr); } ItemChanged?.Invoke(this, null); }
private void SetItemInternal(object item, double previewScale, int themeCategory) { m_prt = item as IPointRule; m_lrt = item as ILineRule; m_art = item as IAreaRule; m_comp = item as ICompositeRule; try { m_isUpdating = true; if (m_prt != null) { RuleCondition.Text = m_prt.Filter; LegendLabel.Text = m_prt.LegendLabel; Image w2d = null; if (m_prt.PointSymbolization2D != null) { //Determine if this is a w2d symbol style if (m_prt.PointSymbolization2D.Symbol.Type == PointSymbolType.W2D) { var sym = (IW2DSymbol)m_prt.PointSymbolization2D.Symbol; w2d = SymbolPicker.GetSymbol(_conn, sym.W2DSymbol.ResourceId, sym.W2DSymbol.LibraryItemName); } } FeatureStyle.SetItem(m_prt, m_prt.PointSymbolization2D, w2d, previewScale, themeCategory); LabelStyle.SetItem(m_prt, m_prt.Label, previewScale, themeCategory); LabelStyle.Visible = true; } else if (m_lrt != null) { RuleCondition.Text = m_lrt.Filter; LegendLabel.Text = m_lrt.LegendLabel; FeatureStyle.SetItem(m_lrt, m_lrt.Strokes, previewScale, themeCategory); LabelStyle.SetItem(m_lrt, m_lrt.Label, previewScale, themeCategory); LabelStyle.Visible = true; } else if (m_art != null) { RuleCondition.Text = m_art.Filter; LegendLabel.Text = m_art.LegendLabel; FeatureStyle.SetItem(m_art, m_art.AreaSymbolization2D, previewScale, themeCategory); LabelStyle.SetItem(m_art, m_art.Label, previewScale, themeCategory); LabelStyle.Visible = true; } else if (m_comp != null) { RuleCondition.Text = m_comp.Filter; LegendLabel.Text = m_comp.LegendLabel; FeatureStyle.SetItem(m_comp, m_comp.CompositeSymbolization, previewScale, themeCategory); LabelStyle.Visible = false; } } finally { m_isUpdating = false; } }
private void ReSyncRulesToBindingList(IVectorStyle style) { _rules.Clear(); if (style != null) { switch (style.StyleType) { case StyleType.Point: { for (int i = 0; i < style.RuleCount; i++) { IPointRule pr = (IPointRule)style.GetRuleAt(i); _rules.Add(new PointRuleModel(pr, i)); } } break; case StyleType.Line: { for (int i = 0; i < style.RuleCount; i++) { ILineRule lr = (ILineRule)style.GetRuleAt(i); _rules.Add(new LineRuleModel(lr, i)); } } break; case StyleType.Area: { for (int i = 0; i < style.RuleCount; i++) { IAreaRule ar = (IAreaRule)style.GetRuleAt(i); _rules.Add(new AreaRuleModel(ar, i)); } } break; case StyleType.Composite: { for (int i = 0; i < style.RuleCount; i++) { ICompositeRule cr = (ICompositeRule)style.GetRuleAt(i); _rules.Add(new CompositeRuleModel(cr, i)); } } break; } } else { _rules.Clear(); } }
private void IdentifyColorSource(ICompositeRule template, ref FillColorSource? source, ref string fillAlpha) { // FIXME: This is very naive. It will identify the first color it finds and runs with it. // It doesn't take into consideration things such as usage contexts, which we currently only care about on // the 2nd pass when we still can't identify a color and presumably we're dealing with a composite symbolization // with line usage (where fill colors won't exist most of the time). Thematics should be fine on the most basic // of composite symbolization cases, but I expect this process to break down hardcore on the most elaborate of // composite symbolization cases. Still, some thematic support is better than none. // So anyways, 1st pass: Assume point/area and identify the first fill color we find foreach (ISymbolInstance symInst in template.CompositeSymbolization.SymbolInstance) { if (source.HasValue) break; var symRef = GetSymbolFromReference(m_editor.ResourceService, symInst.Reference); var simpleSym = symRef as ISimpleSymbolDefinition; if (simpleSym == null) throw new NotSupportedException(Strings.CannotCreateThemeFromCompoundSymbolInstance); var symName = simpleSym.Name; //Find the first path graphic with a fill color foreach (var graphic in simpleSym.Graphics) { if (source.HasValue) break; if (graphic.Type == GraphicElementType.Path) { IPathGraphic path = (IPathGraphic)graphic; if (path.FillColor != null) { var hexIdx = path.FillColor.IndexOf("0x"); if (hexIdx >= 0 && hexIdx + 4 < path.FillColor.Length) { fillAlpha = path.FillColor.Substring(hexIdx + 2, 2); source = FillColorSource.PathFillColor; } else { string color = path.FillColor; //Is this a parameter? if (color.StartsWith("%") && color.EndsWith("%")) { string paramName = color.Substring(1, color.Length - 2); if (simpleSym.ParameterDefinition != null) { foreach (var paramDef in simpleSym.ParameterDefinition.Parameter) { if (source.HasValue) break; if (paramDef.Name == paramName) { hexIdx = paramDef.DefaultValue.IndexOf("0x"); if (hexIdx >= 0 && hexIdx + 4 < paramDef.DefaultValue.Length) { fillAlpha = paramDef.DefaultValue.Substring(hexIdx + 2, 2); source = FillColorSource.SymbolParameterFillColorDefaultValue; } //But wait ... Is there an override for this too? var ov = symInst.ParameterOverrides; if (ov != null) { foreach (var pov in ov.Override) { if (pov.SymbolName == symName && pov.ParameterIdentifier == paramName) { hexIdx = pov.ParameterValue.IndexOf("0x"); if (hexIdx >= 0 && hexIdx + 4 < pov.ParameterValue.Length) { fillAlpha = pov.ParameterValue.Substring(hexIdx + 2, 2); source = FillColorSource.SymbolParameterFillColorOverride; break; } } } } } } } } } } } } } if (!source.HasValue) { //Still no source? Time for a 2nd pass, this time find the first line color where the symbol instance has a line usage //context foreach (ISymbolInstance symInst in template.CompositeSymbolization.SymbolInstance) { if (source.HasValue) break; var symRef = GetSymbolFromReference(m_editor.ResourceService, symInst.Reference); var simpleSym = symRef as ISimpleSymbolDefinition; if (simpleSym == null) throw new NotSupportedException(Strings.CannotCreateThemeFromCompoundSymbolInstance); var symName = simpleSym.Name; //Find the first path graphic with a fill color foreach (var graphic in simpleSym.Graphics) { if (source.HasValue) break; if (graphic.Type == GraphicElementType.Path) { IPathGraphic path = (IPathGraphic)graphic; if (path.LineColor != null) { //Bail on this symbol if it has no line usage context if (simpleSym.LineUsage == null) continue; var hexIdx = path.LineColor.IndexOf("0x"); if (hexIdx >= 0 && hexIdx + 4 < path.LineColor.Length) { fillAlpha = path.LineColor.Substring(hexIdx + 2, 2); source = FillColorSource.PathLineColor; } else { string color = path.LineColor; //Is this a parameter? if (color.StartsWith("%") && color.EndsWith("%")) { string paramName = color.Substring(1, color.Length - 2); if (simpleSym.ParameterDefinition != null) { foreach (var paramDef in simpleSym.ParameterDefinition.Parameter) { if (source.HasValue) break; if (paramDef.Name == paramName) { hexIdx = paramDef.DefaultValue.IndexOf("0x"); if (hexIdx >= 0 && hexIdx + 4 < paramDef.DefaultValue.Length) { fillAlpha = paramDef.DefaultValue.Substring(hexIdx + 2, 2); source = FillColorSource.SymbolParameterLineColorDefaultValue; } //But wait ... Is there an override for this too? var ov = symInst.ParameterOverrides; if (ov != null) { foreach (var pov in ov.Override) { if (pov.SymbolName == symName && pov.ParameterIdentifier == paramName) { hexIdx = pov.ParameterValue.IndexOf("0x"); if (hexIdx >= 0 && hexIdx + 4 < pov.ParameterValue.Length) { fillAlpha = pov.ParameterValue.Substring(hexIdx + 2, 2); source = FillColorSource.SymbolParameterLineColorOverride; break; } } } } } } } } } } } } } } }
private ICompositeRule CreateCompositeRule(ICompositeRule template, ILayerElementFactory2 factory) { var crule = factory.CreateDefaultCompositeRule(); if (template.CompositeSymbolization != null) crule.CompositeSymbolization = factory.CloneCompositeSymbolization(template.CompositeSymbolization); return crule; }
private void SetColorForCompositeRule(FillColorSource? source, string fillAlpha, RuleItem entry, ICompositeRule r) { // NOTE: Same naivete as IdentifyColorSource(). Refer to that method for all the gory details bool bSetFill = false; foreach (ISymbolInstance symInst in r.CompositeSymbolization.SymbolInstance) { if (bSetFill) break; var symRef = GetSymbolFromReference(m_editor.ResourceService, symInst.Reference); var simpleSym = symRef as ISimpleSymbolDefinition; if (simpleSym == null) throw new NotSupportedException(Strings.CannotCreateThemeFromCompoundSymbolInstance); var symName = simpleSym.Name; //Find the first path graphic with a fill color foreach (var graphic in simpleSym.Graphics) { if (bSetFill) break; if (graphic.Type == GraphicElementType.Path) { IPathGraphic path = (IPathGraphic)graphic; if (path.FillColor != null) { string color = path.FillColor; if (source.Value == FillColorSource.PathFillColor) { path.FillColor = "0x" + fillAlpha + Utility.SerializeHTMLColor(entry.Color, string.IsNullOrEmpty(fillAlpha)); Debug.WriteLine(string.Format("Set fill color to {0} for symbol instance {1} of symbolization {2} in rule {3}", path.FillColor, symInst.GetHashCode(), r.CompositeSymbolization.GetHashCode(), r.GetHashCode())); bSetFill = true; break; } //Is this a parameter? if (color.StartsWith("%") && color.EndsWith("%")) { string paramName = color.Substring(1, color.Length - 2); if (simpleSym.ParameterDefinition != null) { foreach (var paramDef in simpleSym.ParameterDefinition.Parameter) { if (bSetFill) break; if (paramDef.Name == paramName) { if (source.Value == FillColorSource.SymbolParameterFillColorDefaultValue) { paramDef.DefaultValue = "0x" + fillAlpha + Utility.SerializeHTMLColor(entry.Color, string.IsNullOrEmpty(fillAlpha)); Debug.WriteLine(string.Format("Set fill color default parameter value to {0} for symbol instance {1} of symbolization {2} in rule {3}", paramDef.DefaultValue, symInst.GetHashCode(), r.CompositeSymbolization.GetHashCode(), r.GetHashCode())); bSetFill = true; break; } //But wait ... Is there an override for this too? var ov = symInst.ParameterOverrides; if (ov != null) { foreach (var pov in ov.Override) { if (bSetFill) break; if (pov.SymbolName == symName && pov.ParameterIdentifier == paramName) { if (source.Value == FillColorSource.SymbolParameterFillColorOverride) { pov.ParameterValue = "0x" + fillAlpha + Utility.SerializeHTMLColor(entry.Color, string.IsNullOrEmpty(fillAlpha)); Debug.WriteLine(string.Format("Set fill color parameter override value to {0} for symbol instance {1} of symbolization {2} in rule {3}", pov.ParameterValue, symInst.GetHashCode(), r.CompositeSymbolization.GetHashCode(), r.GetHashCode())); bSetFill = true; break; } } } } } } } } } else if (path.LineColor != null && simpleSym.LineUsage != null) { string color = path.LineColor; if (source.Value == FillColorSource.PathLineColor) { path.LineColor = "0x" + fillAlpha + Utility.SerializeHTMLColor(entry.Color, string.IsNullOrEmpty(fillAlpha)); Debug.WriteLine(string.Format("Set line color to {0} for symbol instance {1} of symbolization {2} in rule {3}", path.FillColor, symInst.GetHashCode(), r.CompositeSymbolization.GetHashCode(), r.GetHashCode())); bSetFill = true; break; } //Is this a parameter? if (color.StartsWith("%") && color.EndsWith("%")) { string paramName = color.Substring(1, color.Length - 2); if (simpleSym.ParameterDefinition != null) { foreach (var paramDef in simpleSym.ParameterDefinition.Parameter) { if (bSetFill) break; if (paramDef.Name == paramName) { if (source.Value == FillColorSource.SymbolParameterLineColorDefaultValue) { paramDef.DefaultValue = "0x" + fillAlpha + Utility.SerializeHTMLColor(entry.Color, string.IsNullOrEmpty(fillAlpha)); Debug.WriteLine(string.Format("Set line color default parameter value to {0} for symbol instance {1} of symbolization {2} in rule {3}", paramDef.DefaultValue, symInst.GetHashCode(), r.CompositeSymbolization.GetHashCode(), r.GetHashCode())); bSetFill = true; break; } //But wait ... Is there an override for this too? var ov = symInst.ParameterOverrides; if (ov != null) { foreach (var pov in ov.Override) { if (bSetFill) break; if (pov.SymbolName == symName && pov.ParameterIdentifier == paramName) { if (source.Value == FillColorSource.SymbolParameterLineColorOverride) { pov.ParameterValue = "0x" + fillAlpha + Utility.SerializeHTMLColor(entry.Color, string.IsNullOrEmpty(fillAlpha)); Debug.WriteLine(string.Format("Set line color parameter override value to {0} for symbol instance {1} of symbolization {2} in rule {3}", pov.ParameterValue, symInst.GetHashCode(), r.CompositeSymbolization.GetHashCode(), r.GetHashCode())); bSetFill = true; break; } } } } } } } } } } } } }
private void ReSyncBindingListToRules(IVectorStyle style) { if (style != null) { switch (style.StyleType) { case StyleType.Point: { IPointVectorStyle pts = style as IPointVectorStyle; pts.RemoveAllRules(); for (int i = 0; i < _rules.Count; i++) { ILabeledRuleModel rule = (ILabeledRuleModel)_rules[i]; IPointRule pr = (IPointRule)rule.UnwrapRule(); pts.AddRule(pr); rule.SetIndex(i); } } break; case StyleType.Line: { ILineVectorStyle lts = style as ILineVectorStyle; lts.RemoveAllRules(); for (int i = 0; i < _rules.Count; i++) { ILabeledRuleModel rule = (ILabeledRuleModel)_rules[i]; ILineRule lr = (ILineRule)rule.UnwrapRule(); lts.AddRule(lr); rule.SetIndex(i); } } break; case StyleType.Area: { IAreaVectorStyle ats = style as IAreaVectorStyle; ats.RemoveAllRules(); for (int i = 0; i < _rules.Count; i++) { ILabeledRuleModel rule = (ILabeledRuleModel)_rules[i]; IAreaRule ar = (IAreaRule)rule.UnwrapRule(); ats.AddRule(ar); rule.SetIndex(i); } } break; case StyleType.Composite: { ICompositeTypeStyle cts = style as ICompositeTypeStyle; cts.RemoveAllRules(); for (int i = 0; i < _rules.Count; i++) { IRuleModel rule = (IRuleModel)_rules[i]; ICompositeRule cr = (ICompositeRule)rule.UnwrapRule(); cts.AddCompositeRule(cr); rule.SetIndex(i); } } break; } } }
public void SetItem(ICompositeRule parent, ICompositeSymbolization comp, double previewScale, int themeCategory) { isComp = true; SetItemInternal(parent, comp, previewScale, themeCategory); }
private void Rule_ItemDeleted(object sender, EventArgs e) { foreach (Condition c in this.Controls) { if (c.Item == sender) { this.Controls.Remove(c); break; } } if (m_point != null) { IPointRule remove = null; foreach (var pr in m_point.Rules) { if (pr == sender) { remove = pr; break; } } if (remove != null) { m_point.RemoveRule(remove); } } else if (m_line != null) { ILineRule remove = null; foreach (var lr in m_line.Rules) { if (lr == sender) { remove = lr; break; } } if (remove != null) { m_line.RemoveRule(remove); } } else if (m_area != null) { IAreaRule remove = null; foreach (var ar in m_area.Rules) { if (ar == sender) { remove = ar; break; } } if (remove != null) { m_area.RemoveRule(remove); } } else if (m_comp != null) { ICompositeRule remove = null; foreach (var comp in m_comp.CompositeRule) { if (comp == sender) { remove = comp; break; } } if (remove != null) { m_comp.RemoveCompositeRule(remove); } } SignalItemChanged(); }
public void SetItem(ICompositeRule comp, double previewScale, int themeCategory) { SetItemInternal(comp, previewScale, themeCategory); }
public CompositeRuleModel(ICompositeRule rule, int index) { _rule = rule; this.Index = index; this.HasStyle = (_rule.CompositeSymbolization != null); }