Example #1
0
        private void btnAddRule_Click(object sender, EventArgs e)
        {
            switch (_style.StyleType)
            {
            case StyleType.Point:
            {
                var rule = _editedLayer.CreateDefaultPointRule();
                ((IPointVectorStyle)_style).AddRule(rule);
                var model = new PointRuleModel(rule, _style.RuleCount - 1);
                _rules.Add(model);
            }
            break;

            case StyleType.Line:
            {
                var rule = _editedLayer.CreateDefaultLineRule();
                ((ILineVectorStyle)_style).AddRule(rule);
                var model = new LineRuleModel(rule, _style.RuleCount - 1);
                _rules.Add(model);
            }
            break;

            case StyleType.Area:
            {
                var rule = _editedLayer.CreateDefaultAreaRule();
                ((IAreaVectorStyle)_style).AddRule(rule);
                var model = new AreaRuleModel(rule, _style.RuleCount - 1);
                _rules.Add(model);
            }
            break;

            case StyleType.Composite:
            {
                var rule = _editedLayer.CreateDefaultCompositeRule();
                ((ICompositeTypeStyle)_style).AddCompositeRule(rule);
                var model = new CompositeRuleModel(rule, _style.RuleCount - 1);
                _rules.Add(model);
            }
            break;
            }
        }
Example #2
0
        private void EditRuleStyle(RuleModel rule)
        {
            PointRuleModel     pr = rule as PointRuleModel;
            LineRuleModel      lr = rule as LineRuleModel;
            AreaRuleModel      ar = rule as AreaRuleModel;
            CompositeRuleModel cr = rule as CompositeRuleModel;

            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
                                                                    this.ThemeIndexOffest + 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;

            if (pr != null)
            {
                var sym = pr.GetSymbolizationStyle();

                m_origPoint = sym;
                m_editPoint = (sym == null) ? null : (IPointSymbolization2D)sym.Clone();

                var pfse = new PointFeatureStyleEditor(_edSvc, clsDef, vl.ResourceId, pr.Style, prev);
                uc        = pfse;
                pfse.Item = m_editPoint;

                Action editCommit = () =>
                {
                    m_editPoint = pfse.Item;
                    pr.SetSymbolizationStyle(m_editPoint);
                };
                pfse.SetEditCommit(editCommit);
                commit = () =>
                {
                    pr.SetSymbolizationStyle(pfse.Item);
                    _edSvc.HasChanged();
                    UpdateRulePreviewAsync(pr);
                };
                rollback = () =>
                {
                    pr.SetSymbolizationStyle(m_origPoint);
                };
            }
            else if (lr != null)
            {
                var lineSym = lr.GetSymbolizationStyle();
                var strokes = lineSym.Strokes;
                m_origLine = strokes;
                m_editLine = (strokes == null) ? new List <IStroke>() : LayerElementCloningUtil.CloneStrokes(strokes);

                var lfse = new LineFeatureStyleEditor(_edSvc, clsDef, vl.ResourceId, _editedLayer, prev);
                uc        = lfse;
                lfse.Item = m_editLine;

                Action editCommit = () =>
                {
                    m_editLine = lfse.Item;
                    lineSym.SetStrokes(m_editLine);
                };
                lfse.SetEditCommit(editCommit);
                commit = () =>
                {
                    lineSym.SetStrokes(lfse.Item);
                    _edSvc.HasChanged();
                    UpdateRulePreviewAsync(lr);
                };
                rollback = () =>
                {
                    lineSym.SetStrokes(m_origLine);
                };
            }
            else if (ar != null)
            {
                var area = ar.GetSymbolizationStyle();

                m_origArea = area;
                m_editArea = (area == null) ? null : (IAreaSymbolizationFill)area.Clone();

                var afse = new AreaFeatureStyleEditor(_edSvc, clsDef, vl.ResourceId, prev);
                uc        = afse;
                afse.Item = m_editArea;

                Action editCommit = () =>
                {
                    m_editArea = afse.Item;
                    ar.SetSymbolizationStyle(m_editArea);
                };
                commit = () =>
                {
                    ar.SetSymbolizationStyle(afse.Item);
                    _edSvc.HasChanged();
                    UpdateRulePreviewAsync(ar);
                };
                rollback = () =>
                {
                    ar.SetSymbolizationStyle(m_origArea);
                };
                afse.SetEditCommit(editCommit);
            }
            else if (cr != null)
            {
                var diag = new SymbolInstancesDialog(_edSvc, cr.GetSymbolizationStyle(), GetLayerClass(), GetLayerProvider(), vl.ResourceId, prev);
                diag.ShowDialog();
                //HACK: Assume edits made
                _edSvc.HasChanged();
                UpdateRulePreviewAsync(cr);
                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 (pr != null)
                    {
                        _edSvc.HasChanged();
                    }
                    else if (lr != null)
                    {
                        _edSvc.HasChanged();
                    }
                    else if (ar != null)
                    {
                        _edSvc.HasChanged();
                    }
                }
                else if (res == DialogResult.Cancel)
                {
                    if (rollback != null)
                    {
                        rollback.Invoke();
                    }
                }
            }
        }