Ejemplo n.º 1
0
        /// <summary>
        /// Make sure the changes in the text tab can be parsed correctly
        /// </summary>
        /// <returns>True if the text is correct</returns>
        private bool ValidateTextContents()
        {
            if (textChanged || StyleLibrary.Styles == null)
            {
                try
                {
                    isTextValidating = true;
                    StyleLibrary.ApplyTextContents(scintillaControl.Text);
                    textChanged = false;
                    SetStyleLibModified(true);
                    timerRefresh.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + ". Please correct the issue in the text tab.", "MapManager",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);

                    tabControl.SelectedIndex = 1;
                    return(false);
                }
                finally
                {
                    isTextValidating = false;
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// FormClosing Event handler for the StyleLibraryForm object.
 /// </summary>
 /// <param name="sender">The source object of this event.</param>
 /// <param name="e">Event parameters.</param>
 private void StyleLibraryForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (styleLibraryChanged)
     {
         DialogResult result = MessageBox.Show("The Style Library has been edited, would you like to save the changes?", "MapManager",
                                               MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
         try
         {
             if (result == DialogResult.Yes)
             {
                 SaveAll();
             }
             else if (result == DialogResult.No)
             {
                 StyleLibrary.Refresh(); // reload
             }
             else if (result == DialogResult.Cancel)
             {
                 e.Cancel = true;
                 return;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             e.Cancel = true;
             return;
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// SelectedIndexChanged Event handler for the tabControl object.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">Event parameters.</param>
        private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (isTextValidating)
            {
                return;
            }

            buttonAddFont.Visible    = false;
            buttonRemoveFont.Visible = false;

            if (tabControl.SelectedIndex == 0)
            {
                ValidateTextContents();
                buttonSave.Enabled = styleLibraryChanged;
            }
            else if (tabControl.SelectedIndex == 1)
            {
                string txt = StyleLibrary.LoadTextContents();
                if (scintillaControl.Text != txt)
                {
                    isInitStyleLibText    = true;
                    scintillaControl.Text = txt;
                    SetMargins();

                    if (caretPos > 0)
                    {
                    }

                    textChanged        = false;
                    isInitStyleLibText = false;
                }
                scintillaControl.Focus();
                textChanged        = false;
                buttonSave.Enabled = styleLibraryChanged;
            }
            else if (tabControl.SelectedIndex == 2)
            {
                buttonSave.Enabled = false;
            }
            else if (tabControl.SelectedIndex == 3)
            {
                buttonSave.Enabled       = false;
                buttonAddFont.Visible    = true;
                buttonRemoveFont.Visible = true;
                buttonRemoveFont.Enabled = (listViewFonts.SelectedItems.Count > 0);
            }

            if (tabControl.SelectedIndex != 3 && fontsetChanged)
            {
                if (MessageBox.Show("Do you wish to save the modifications of the symbolset?", "MapManager", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    SaveFontset();
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Saving the symbolset to file
 /// </summary>
 private void SaveSymbolset()
 {
     if (StyleLibrary.SymbolsetFileName != null && symbolsetChanged)
     {
         File.WriteAllText(StyleLibrary.SymbolsetFileName, scintillaControlSymbolset.Text);
         // reconstruct the in memory style lib with this new symbolset (without writing a file)
         string text = StyleLibrary.LoadTextContents();
         StyleLibrary.ApplyTextContents(text);
         layerControlStyles.Target = StyleLibrary.Styles;
         SetSymbolsetModified(false);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Saving both the Style Library and the Symbolset (if changed)
        /// </summary>
        private void SaveAll()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                StyleLibrary.Save();
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Saving the fontset to file
 /// </summary>
 private void SaveFontset()
 {
     if (StyleLibrary.FontsetFileName != null && fontsetChanged)
     {
         StringBuilder fontsetContents = new StringBuilder();
         foreach (ListViewItem item in listViewFonts.Items)
         {
             fontsetContents.AppendLine(String.Format("{0}\t{1}", item.Text, item.SubItems[1].Text));
         }
         File.WriteAllText(StyleLibrary.FontsetFileName, fontsetContents.ToString());
         // reconstruct the in memory style lib with this new fontset (without writing a file)
         string text = StyleLibrary.LoadTextContents();
         StyleLibrary.ApplyTextContents(text);
         layerControlStyles.Target = StyleLibrary.Styles;
         SetFontsetModified(false);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Refresh event handler of the timerRefresh control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="layer">The selected layer.</param>
        private void timerRefresh_Tick(object sender, EventArgs e)
        {
            timerRefresh.Enabled = false;

            try
            {
                this.Cursor          = Cursors.WaitCursor;
                panelRefresh.Visible = true;
                Application.DoEvents();
                if (isInit)
                {
                    StyleLibrary.Refresh();
                    StyleLibrary.Styles.PropertyChanged += Styles_PropertyChanged;
                    isInit = false;
                }
                layerControlStyles.Target = StyleLibrary.Styles;
            }
            finally
            {
                this.Cursor          = Cursors.Default;
                panelRefresh.Visible = false;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            if (style == null)
            {
                return;
            }
            //STEPH: set first load flag to make sure values are not updated by listView_SelectedIndexChanged event
            firstLoad = true;

            if (style.size < 0) // set default size (#4339)
            {
                textBoxSize.Text = "8";
            }
            else
            {
                textBoxSize.Text = style.size.ToString();
            }
            styleBindingControllerSize.InitializeBinding(target);

            textBoxMinSize.Text = style.minsize.ToString();
            textBoxMaxSize.Text = style.maxsize.ToString();
            textBoxWidth.Text   = style.width.ToString();
            styleBindingControllerWidth.InitializeBinding(target);
            textBoxAngle.Text = style.angle.ToString();
            styleBindingControllerAngle.InitializeBinding(target);
            textBoxMinWidth.Text = style.minwidth.ToString();
            textBoxMaxWidth.Text = style.maxwidth.ToString();
            textBoxOffsetX.Text  = style.offsetx.ToString();
            textBoxOffsetY.Text  = style.offsety.ToString();

            this.colorPickerColor.SetColor(style.color);
            styleBindingControllerColor.InitializeBinding(target);
            this.colorPickerBackColor.SetColor(style.backgroundcolor);
            this.colorPickerOutlineColor.SetColor(style.outlinecolor);
            styleBindingControllerOutlineColor.InitializeBinding(target);
            trackBarOpacity.Value    = style.opacity;
            labelOpacityPercent.Text = trackBarOpacity.Value + "%";

            checkBoxAutoAngle.Checked = (style.autoangle == mapscript.MS_TRUE);

            comboBoxGeomTransform.Items.Clear();
            if (isLabelStyle)
            {
                comboBoxGeomTransform.Items.AddRange(new string[] { "labelpnt", "labelpoly" });
            }
            else
            {
                comboBoxGeomTransform.Items.AddRange(new string[] { "start", "end", "vertices", "bbox", "centroid" });
            }

            comboBoxGeomTransform.Text = style.getGeomTransform();
            textBoxGap.Text            = style.gap.ToString();

            textBoxPattern.Text = GetPattenString(style.pattern);

            if (style.minscaledenom >= 0)
            {
                textBoxMinZoom.Text = style.minscaledenom.ToString();
            }
            else
            {
                textBoxMinZoom.Text = "";
            }
            if (style.maxscaledenom >= 0)
            {
                textBoxMaxZoom.Text = style.maxscaledenom.ToString();
            }
            else
            {
                textBoxMaxZoom.Text = "";
            }

            // populate the category combo
            mapObj styles           = StyleLibrary.Styles;
            string selectedCategory = null;
            bool   isStyleSelected  = false;

            for (int i = styles.numlayers - 1; i > -1; i--)
            {
                layerObj stylelayer = styles.getLayer(i);
                if (isLabelStyle)
                {
                    // for label styles add polygon and point categories
                    if (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON ||
                        stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                    {
                        comboBoxCategory.Items.Add(stylelayer.name);
                    }
                    if (selectedCategory == null && ((stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON && style.getGeomTransform().Contains("labelpoly")) ||
                                                     (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POINT && style.getGeomTransform().Contains("labelpnt"))))
                    {
                        selectedCategory = stylelayer.name; // for label style select default
                    }
                }
                else if ((layer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON ||
                          layer.type == MS_LAYER_TYPE.MS_LAYER_CIRCLE) &&
                         (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON ||
                          stylelayer.type == MS_LAYER_TYPE.MS_LAYER_LINE))
                {
                    comboBoxCategory.Items.Add(stylelayer.name);
                    if (selectedCategory == null)
                    {
                        selectedCategory = stylelayer.name; // for polygon layers select default
                    }
                }
                else if (layer.type == MS_LAYER_TYPE.MS_LAYER_LINE &&
                         stylelayer.type == MS_LAYER_TYPE.MS_LAYER_LINE)
                {
                    comboBoxCategory.Items.Add(stylelayer.name);
                    if (selectedCategory == null)
                    {
                        selectedCategory = stylelayer.name; // for line layers select default
                    }
                }
                else if (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    comboBoxCategory.Items.Add(stylelayer.name);
                    if (selectedCategory == null)
                    {
                        selectedCategory = stylelayer.name; // for point layers select default
                    }
                }

                // select the style
                if (style.symbolname != null)
                {
                    for (int c = 0; c < stylelayer.numclasses; c++)
                    {
                        classObj styleclass = stylelayer.getClass(c);
                        styleObj libstyle   = styleclass.getStyle(0);

                        if (style.symbolname == libstyle.symbolname)
                        {
                            selectedCategory = stylelayer.name;
                            isStyleSelected  = true;
                            break;
                        }
                    }
                }
            }
            // check if we have inline symbols added to the map file
            bool inlineAdded = false;

            for (int i = 0; i < map.symbolset.numsymbols; i++)
            {
                symbolObj symbol = map.symbolset.getSymbol(i);
                if (symbol.inmapfile == mapscript.MS_TRUE &&
                    !StyleLibrary.HasSymbol(symbol.name))
                {
                    if (!inlineAdded)
                    {
                        comboBoxCategory.Items.Add("Inline Symbols");
                        inlineAdded = true;
                    }
                    if (!isStyleSelected && style.symbolname == symbol.name)
                    {
                        selectedCategory = "Inline Symbols";
                    }
                }
            }

            if (selectedCategory != null)
            {
                comboBoxCategory.SelectedItem = selectedCategory;
            }
            else if (comboBoxCategory.Items.Count > 0)
            {
                comboBoxCategory.SelectedIndex = 0;
            }

            SetDirty(false);
        }
Ejemplo n.º 9
0
        private void UpdateStyleList()
        {
            string selectedName = style.symbolname;

            if (listView.SelectedItems.Count > 0)
            {
                selectedName = listView.SelectedItems[0].Text;
            }

            // populate the style listview
            listView.Items.Clear();
            imageList.Images.Clear();

            ListViewItem selected = null;

            if (comboBoxCategory.Text != "")
            {
                // Create "no symbol" entry
                styleObj nosymbolstyle = new styleObj(null);
                MapUtils.SetDefaultColor(layer.type, nosymbolstyle);
                ListViewItem nosymbolitem = AddListItem(nosymbolstyle, layer, "Default");
                if (selectedName == null)
                {
                    selected = nosymbolitem;
                }

                if (comboBoxCategory.Text == "Inline Symbols")
                {
                    for (int i = 0; i < map.symbolset.numsymbols; i++)
                    {
                        symbolObj symbol = map.symbolset.getSymbol(i);
                        if (symbol.inmapfile == mapscript.MS_TRUE &&
                            !StyleLibrary.HasSymbol(symbol.name))
                        {
                            styleObj libstyle = new styleObj(null);
                            //if (symbol.type == (int)MS_SYMBOL_TYPE.MS_SYMBOL_PATTERNMAP)
                            //    MapUtils.SetDefaultColor(MS_LAYER_TYPE.MS_LAYER_LINE, libstyle);
                            //else
                            MapUtils.SetDefaultColor(layer.type, libstyle);
                            libstyle.setSymbolByName(map, symbol.name);
                            libstyle.size = 8;
                            MS_LAYER_TYPE type = layer.type;
                            try
                            {
                                //STEPH: change layer passed to the list view to be consistent with the other symbol categories
                                //so that it uses a point layer to display the style in the list
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                                ListViewItem item = AddListItem(libstyle, layer, symbol.name);
                                if (selectedName == item.Text)
                                {
                                    selected = item;
                                }
                            }
                            finally
                            {
                                layer.type = type;
                            }
                        }
                    }
                }
                else
                {
                    // collect all fonts specified in the fontset file
                    Hashtable fonts = new Hashtable();
                    string    key   = null;
                    while ((key = map.fontset.fonts.nextKey(key)) != null)
                    {
                        fonts.Add(key, key);
                    }

                    mapObj   styles     = StyleLibrary.Styles;
                    layerObj stylelayer = styles.getLayerByName(comboBoxCategory.Text);
                    for (int i = 0; i < stylelayer.numclasses; i++)
                    {
                        classObj classobj    = stylelayer.getClass(i);
                        int      symbolIndex = classobj.getStyle(0).symbol;
                        if (symbolIndex >= 0)
                        {
                            string font = styles.symbolset.getSymbol(symbolIndex).font;
                            if (font != null && !fonts.ContainsKey(font))
                            {
                                continue; // this font cannot be found in fontset
                            }
                        }

                        ListViewItem item = AddListItem(classobj.getStyle(0), stylelayer, classobj.name);
                        if (selectedName == item.Text)
                        {
                            selected = item;
                        }
                    }
                }
            }

            if (selected != null)
            {
                selected.Selected = true;
                selected.EnsureVisible();
            }
        }