Beispiel #1
0
        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();
                    }
                }
            }
        }