public object Clone(CloneOptions options) { SimpleLabelRenderer renderer = new SimpleLabelRenderer( (ITextSymbol)((_symbol is IClone2) ? _symbol.Clone(options) : null), _fieldname); renderer._howManyLabels = _howManyLabels; renderer._labelPriority = _labelPriority; renderer._fontField = _fontField; renderer._sizeField = _sizeField; renderer._expression = _expression; renderer._useExpression = _useExpression; renderer._symbolRotation = (SymbolRotation)_symbolRotation.Clone(); renderer._clipEnvelope = _clipEnvelope != null ? new Envelope(_clipEnvelope) : null; renderer._lineLabelling = _lineLabelling; return(renderer); }
private void EditLabelStyle(RuleModel rule) { PointRuleModel pr = rule as PointRuleModel; LineRuleModel lr = rule as LineRuleModel; AreaRuleModel ar = rule as AreaRuleModel; UserControl uc = null; /* * if (m_owner.SelectedClass == null) * { * MessageBox.Show(Strings.NoFeatureClassAssigned); * return; * }*/ var previewScale = 0.0; if (_parentScaleRange.MinScale.HasValue) { previewScale = _parentScaleRange.MinScale.Value; } ILayerStylePreviewable prev = new LayerStylePreviewable(_edSvc.EditedResourceID, previewScale, 80, 40, "PNG", //NOXLATE rule.Index); //TODO: This is obviously a mess and could do with some future cleanup, but the idea here should be //easy to understand. Each primitive basic style (that's not a label) has 3 actions. // - Commit (When user clicks OK on dialog) // - Rollback (When user clicks Cancel on dialog) // - Edit Commit (When user invokes refresh) //Those that support GETLEGENDIMAGE-based previews will be passed an edit commit action. Invoking the //edit commit action will update the session-based layer with this edit-copy rule, allowing for the changes //to be reflected when we do the GETLEGENDIMAGE call // //Labels are exempt as those previews can be sufficiently simulated with System.Drawing API var vl = (IVectorLayerDefinition)_editedLayer.SubLayer; ClassDefinition clsDef = GetLayerClass(); Action commit = null; Action rollback = null; ITextSymbol labelToEdit = null; if (pr != null) { labelToEdit = pr.GetLabelStyle(); } else if (lr != null) { labelToEdit = lr.GetLabelStyle(); } else if (ar != null) { labelToEdit = ar.GetLabelStyle(); } m_origLabel = labelToEdit; m_editLabel = (labelToEdit == null) ? null : (ITextSymbol)labelToEdit.Clone(); uc = new FontStyleEditor(_edSvc, clsDef, vl.ResourceId); ((FontStyleEditor)uc).Item = m_editLabel; if (uc != null) { EditorTemplateForm dlg = new EditorTemplateForm(); dlg.ItemPanel.Controls.Add(uc); uc.Dock = DockStyle.Fill; dlg.RefreshSize(); var res = dlg.ShowDialog(this); if (res == DialogResult.OK) { if (commit != null) { commit.Invoke(); } ITextSymbol editedLabel = ((FontStyleEditor)uc).Item; if (pr != null) { pr.SetLabelStyle(editedLabel); _edSvc.HasChanged(); } else if (lr != null) { lr.SetLabelStyle(editedLabel); _edSvc.HasChanged(); } else if (ar != null) { ar.SetLabelStyle(editedLabel); _edSvc.HasChanged(); } } else if (res == DialogResult.Cancel) { if (rollback != null) { rollback.Invoke(); } } } }
private void EditButton_Click(object sender, EventArgs e) { UserControl uc = null; if (m_owner.SelectedClass == null) { MessageBox.Show(Strings.NoFeatureClassAssigned); return; } ILayerStylePreviewable prev = new LayerStylePreviewable(m_owner.EditorService.EditedResourceID, this.PreviewScale, 80, 40, "PNG", //NOXLATE _themeOffset + this.ThemeCategory); //TODO: This is obviously a mess and could do with some future cleanup, but the idea here should be //easy to understand. Each primitive basic style (that's not a label) has 3 actions. // - Commit (When user clicks OK on dialog) // - Rollback (When user clicks Cancel on dialog) // - Edit Commit (When user invokes refresh) //Those that support GETLEGENDIMAGE-based previews will be passed an edit commit action. Invoking the //edit commit action will update the session-based layer with this edit-copy rule, allowing for the changes //to be reflected when we do the GETLEGENDIMAGE call // //Labels are exempt as those previews can be sufficiently simulated with System.Drawing API var factory = (ILayerElementFactory)m_owner.Editor.GetEditedResource(); Action commit = null; Action rollback = null; if (isLabel) { m_origLabel = m_label; m_editLabel = (m_label == null) ? null : (ITextSymbol)m_label.Clone(); uc = new FontStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId); ((FontStyleEditor)uc).Item = m_editLabel; } else if (isW2dSymbol) { m_origPoint = m_point; m_editPoint = (m_point == null) ? null : (IPointSymbolization2D)m_point.Clone(); var pfse = new PointFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, m_w2dsymbol, prev); uc = pfse; pfse.Item = m_editPoint; Action editCommit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_editPoint = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_editPoint; m_w2dsymbol = w2d; }; pfse.SetEditCommit(editCommit); commit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_point = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_point; m_w2dsymbol = w2d; }; rollback = () => { ((IPointRule)m_parent).PointSymbolization2D = m_origPoint; }; } else if (isPoint) { m_origPoint = m_point; m_editPoint = (m_point == null) ? null : (IPointSymbolization2D)m_point.Clone(); var pfse = new PointFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, prev); uc = pfse; pfse.Item = m_editPoint; Action editCommit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_editPoint = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_editPoint; m_w2dsymbol = w2d; }; pfse.SetEditCommit(editCommit); commit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_point = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_point; m_w2dsymbol = w2d; }; rollback = () => { ((IPointRule)m_parent).PointSymbolization2D = m_origPoint; }; } else if (isLine) { m_origLine = m_line; m_editLine = (m_line == null) ? new List <IStroke>() : LayerElementCloningUtil.CloneStrokes(m_line); var lfse = new LineFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, factory, prev); uc = lfse; lfse.Item = m_editLine; Action editCommit = () => { m_editLine = lfse.Item; ((ILineRule)m_parent).SetStrokes(m_editLine); }; lfse.SetEditCommit(editCommit); commit = () => { m_line = lfse.Item; ((ILineRule)m_parent).SetStrokes(m_line); }; rollback = () => { ((ILineRule)m_parent).SetStrokes(m_origLine); }; } else if (isArea) { m_origArea = m_area; m_editArea = (m_area == null) ? null : (IAreaSymbolizationFill)m_area.Clone(); var afse = new AreaFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, prev); uc = afse; afse.Item = m_editArea; Action editCommit = () => { m_editArea = afse.Item; ((IAreaRule)m_parent).AreaSymbolization2D = m_editArea; }; commit = () => { m_area = afse.Item; ((IAreaRule)m_parent).AreaSymbolization2D = m_area; }; rollback = () => { ((IAreaRule)m_parent).AreaSymbolization2D = m_origArea; }; afse.SetEditCommit(editCommit); } else if (isComp) { var diag = new SymbolInstancesDialog(m_owner.Editor, m_comp, m_owner.SelectedClass, m_owner.GetFdoProvider(), m_owner.FeatureSourceId, prev); diag.ShowDialog(); //HACK: Assume edits made Owner.RaiseResourceChanged(); return; } if (uc != null) { EditorTemplateForm dlg = new EditorTemplateForm(); dlg.ItemPanel.Controls.Add(uc); uc.Dock = DockStyle.Fill; dlg.RefreshSize(); var res = dlg.ShowDialog(this); if (res == DialogResult.OK) { if (commit != null) { commit.Invoke(); } if (isLabel) { m_label = ((FontStyleEditor)uc).Item; if (m_parent as IPointRule != null) { ((IPointRule)m_parent).Label = m_label; } else if (m_parent as ILineRule != null) { ((ILineRule)m_parent).Label = m_label; } else if (m_parent as IAreaRule != null) { ((IAreaRule)m_parent).Label = m_label; } ItemChanged?.Invoke(m_label, null); } else if (isPoint || isW2dSymbol) { ItemChanged?.Invoke(m_point, null); } else if (isLine) { ItemChanged?.Invoke(m_line, null); } else if (isArea) { ItemChanged?.Invoke(m_area, null); } this.Refresh(); } else if (res == DialogResult.Cancel) { if (rollback != null) { rollback.Invoke(); } } } }