Exemple #1
0
    public void testGetStyleObjDestroy()
    {
        mapObj   map       = new mapObj(mapfile);
        layerObj layer     = map.getLayer(1);
        classObj classobj  = layer.getClass(0);
        styleObj style     = classobj.getStyle(0);
        styleObj reference = classobj.getStyle(0);

        assert(style.refcount == 3, "testGetStyleObjDestroy precondition");
        map = null; layer = null; classobj = null; style = null;
        gc();
        assert(reference.refcount == 2, "testGetStyleObjDestroy");
    }
        /// <summary>
        /// Have the editor to update the theme on the layer object.
        /// </summary>
        public void UpdateValues()
        {
            if (newLayer != null)
            {
                // remove the auto style from this layer
                layer.styleitem = null;

                while (layer.numclasses > 0)
                {
                    layer.removeClass(layer.numclasses - 1);
                }

                for (int i = 0; i < newLayer.numclasses; i++)
                {
                    classObj classobj = newLayer.getClass(i).clone();
                    // bindings are not supported with sample maps
                    for (int s = 0; s < classobj.numstyles; s++)
                    {
                        StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                    }
                    for (int l = 0; l < classobj.numlabels; l++)
                    {
                        LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                    }
                    layer.insertClass(classobj, -1);
                }

                if (target != null)
                {
                    target.RaisePropertyChanged(this);
                }
            }
        }
Exemple #3
0
    public void testGetStyleObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj classobj = layer.getClass(0);
        styleObj style    = classobj.getStyle(0);

        map = null; layer = null; classobj = null;
        gc();
        assert(style.refcount == 2, "testGetStyleObj");
    }
Exemple #4
0
    public void testStyleObjDestroy()
    {
        mapObj   map       = new mapObj(mapfile);
        layerObj layer     = map.getLayer(1);
        classObj classobj  = layer.getClass(0);
        styleObj newStyle  = new styleObj(classobj);
        styleObj reference = classobj.getStyle(classobj.numstyles - 1);

        assert(newStyle.refcount == 3, "testStyleObjDestroy");
        newStyle.Dispose();         // force the destruction for Mono on Windows because of the constructor overload
        map = null; layer = null; classobj = null; newStyle = null;
        gc();
        assert(reference.refcount == 2, "testStyleObjDestroy");
    }
Exemple #5
0
        /// <summary>
        /// EditProperties Event handler for the layerControlStyles object.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">Event parameters.</param>
        private void layerControlStyles_EditProperties(object sender, MapObjectHolder target)
        {
            try
            {
                MapPropertyEditorForm mapPropertyEditor;
                if (target.GetType() == typeof(classObj))
                {
                    classObj classobj = target;

                    if (classobj.numstyles <= 0)
                    {
                        // adding an empty style to this class
                        styleObj style = new styleObj(classobj);
                    }

                    mapPropertyEditor = new MapPropertyEditorForm(
                        new MapObjectHolder(classobj.getStyle(0), target), new StyleLibraryPropertyEditor());
                }
                else if (target.GetType() == typeof(styleObj))
                {
                    mapPropertyEditor = new MapPropertyEditorForm(target, new StyleLibraryPropertyEditor());
                }
                else
                {
                    return;
                }
                propertyChanged         = false;
                target.PropertyChanged += new EventHandler(target_PropertyChanged);
                mapPropertyEditor.ShowDialog(this);
                if (propertyChanged)
                {
                    layerControlStyles.RefreshView();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemple #6
0
        public static void ExpandFontStyles()
        {
            string        symbolSetFileContents = File.ReadAllText(symbolsetFileName);
            string        fontSetFileContents   = File.ReadAllText(fontsetFileName);
            StringBuilder newSymbols            = new StringBuilder();
            StringBuilder newFonts = new StringBuilder();

            for (int i = 0; i < map.numlayers; i++)
            {
                layerObj layer = map.getLayer(i);
                if (MapUtils.HasMetadata(layer, "character-count"))
                {
                    string charcount = layer.getMetaData("character-count");
                    int    num;
                    if (layer.numclasses == 1 && charcount != null && int.TryParse(charcount, out num))
                    {
                        classObj classobj = layer.getClass(0);
                        if (!fontSetFileContents.Contains(classobj.name))
                        {
                            throw new Exception("Invalid font reference in mmstyles.map: " + classobj.name + ". The fontset file should contain an entry for this font name.");
                        }
                        for (int c = 33; c < 33 + num; c++)
                        {
                            string symbolname = classobj.name + "-" + c.ToString();

                            if (!symbolSetFileContents.Contains(symbolname))
                            {
                                symbolObj sym = new symbolObj(symbolname, null);
                                sym.character = "&#" + c.ToString() + ";";
                                sym.antialias = mapscript.MS_TRUE;
                                sym.type      = (int)MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE;
                                sym.font      = classobj.name;
                                sym.inmapfile = 0;
                                map.symbolset.appendSymbol(sym);
                                newSymbols.Append(String.Format("SYMBOL{0}  NAME \"{1}\"{0}  TYPE TRUETYPE{0}  ANTIALIAS TRUE{0}  CHARACTER \"{2}\"{0}  FONT \"{3}\"{0}END{0}", Environment.NewLine, symbolname, sym.character, sym.font));
                            }
                            if (c > 33)
                            {
                                // the first class is already inserted
                                classObj class2 = classobj.clone();
                                class2.name = symbolname;
                                styleObj style2 = class2.getStyle(0);
                                style2.setSymbolByName(map, symbolname);
                                layer.insertClass(class2, -1);
                            }
                            else
                            {
                                styleObj style2 = classobj.getStyle(0);
                                style2.setSymbolByName(map, symbolname);
                            }
                        }
                        if (!classobj.name.EndsWith("-33"))
                        {
                            classobj.name += "-33";
                        }
                    }
                    layer.removeMetaData("character-count");
                }
            }
            if (newSymbols.Length > 0)
            {
                // writing the new symbols to the symbolset file
                int lastpos = symbolSetFileContents.LastIndexOf("END", StringComparison.InvariantCultureIgnoreCase);
                symbolSetFileContents = symbolSetFileContents.Substring(0, lastpos) + newSymbols.ToString() + "END";
                File.WriteAllText(symbolsetFileName, symbolSetFileContents);
            }
            if (newFonts.Length > 0)
            {
                // writing the new fonts to the fontset file
                File.WriteAllText(fontsetFileName, fontSetFileContents + newFonts.ToString());
            }
        }
Exemple #7
0
        /// <summary>
        /// Validating event handler of the scintillaControlSymbolset control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="layer">The selected layer.</param>
        private void scintillaControlSymbolset_Validating(object sender, CancelEventArgs e)
        {
            if (symbolsetChanged)
            {
                // validating
                string fileName = Path.GetTempFileName();
                try
                {
                    File.WriteAllText(fileName, scintillaControlSymbolset.Text);
                    // test whether we can parse the symbolset
                    symbolSetObj s = new symbolSetObj(fileName);
                    // make sure we have all symbol references
                    Hashtable symbolNames = new Hashtable();
                    for (int i = 0; i < s.numsymbols; i++)
                    {
                        string symbolName = s.getSymbol(i).name;
                        if (symbolName != null && !symbolNames.ContainsKey(symbolName))
                        {
                            symbolNames.Add(symbolName, symbolName);
                        }
                    }
                    mapObj map = StyleLibrary.Styles;
                    s = map.symbolset;
                    for (int i = 0; i < s.numsymbols; i++)
                    {
                        symbolObj sym        = s.getSymbol(i);
                        string    symbolName = sym.name;
                        if (symbolName != null && sym.inmapfile == mapscript.MS_TRUE && !symbolNames.ContainsKey(symbolName))
                        {
                            symbolNames.Add(symbolName, symbolName);
                        }
                    }

                    for (int i = 0; i < map.numlayers; i++)
                    {
                        layerObj layer = map.getLayer(i);
                        for (int j = 0; j < layer.numclasses; j++)
                        {
                            classObj classobj = layer.getClass(j);
                            for (int k = 0; k < classobj.numstyles; k++)
                            {
                                string symbolName = classobj.getStyle(k).symbolname;
                                if (symbolName != null && !symbolNames.ContainsKey(symbolName))
                                {
                                    throw new Exception("Symbol name '" + symbolName + "' is missing from the symbolset file!");
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (MessageBox.Show(ex.Message + "\n\rPress OK to correct the errors or Cancel to ignore the changes!", "MapManager", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
                    {
                        e.Cancel = true;
                    }
                    else
                    {
                        LoadSymbolset();
                    }

                    return;
                }
                finally
                {
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }

                // validation ok, ask whether to save or not
                DialogResult res = MessageBox.Show("Do you wish to save the modifications of the symbolset?", "MapManager", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (res == DialogResult.Yes)
                {
                    SaveSymbolset();
                    // the symbolset has changed, need to reload view
                    timerRefresh.Enabled = true;
                }
                else if (res == DialogResult.No)
                {
                    LoadSymbolset();
                }
                else if (res == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }
        }
Exemple #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;
            checkBoxAntialias.Checked = (style.antialias == mapscript.MS_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);
        }
Exemple #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();
            }
        }
Exemple #10
0
        /// <summary>
        /// Creating a sample (preview) based on a classObj, styleObj or labelObj.
        /// </summary>
        /// <param name="original">The wrapper holding the original object.</param>
        private void CreateSampleMap(MapObjectHolder original)
        {
            MapObjectHolder originalMap = null;
            MapObjectHolder originalLayer = null;
            MapObjectHolder originalClass = null;
            // create a sample map to render a preview of the given object
            if (original.GetType() == typeof(classObj))
            {
                // tracking down the whole object tree
                originalLayer = original.GetParent();
                if (originalLayer != null)
                    originalMap = originalLayer.GetParent();
                // creating a new compatible map object
                if (originalMap != null)
                {
                    layerObj layer = InitializeDefaultLayer(originalMap, originalLayer);
                    layer.insertClass(((classObj)original).clone(), -1);
                    // bindings are not supported with sample maps
                    classObj classobj = layer.getClass(0);
                    for (int i = 0; i < classobj.numstyles; i++)
                        StyleBindingController.RemoveAllBindings(classobj.getStyle(i));
                    for (int i = 0; i < classobj.numlabels; i++)
                        LabelBindingController.RemoveAllBindings(classobj.getLabel(i));
                    classobj.setText("Sample text");
                    classobj.setExpression(""); // remove expression to have the class shown

                    this.target = new MapObjectHolder(classobj, original.GetParent());
                }
            }
            else if (original.GetType() == typeof(styleObj))
            {
                // tracking down the whole object tree
                if (original.GetParent().GetType() == typeof(labelObj))
                    originalClass = original.GetParent().GetParent();
                else
                    originalClass = original.GetParent();
                if (originalClass != null)
                    originalLayer = originalClass.GetParent();
                if (originalLayer != null)
                    originalMap = originalLayer.GetParent();
                // creating a new compatible map object
                if (originalMap != null)
                {
                    layerObj layer = InitializeDefaultLayer(originalMap, originalLayer);
                    classObj classobj = new classObj(layer);
                    classobj.name = MapUtils.GetClassName(layer);
                    styleObj style;
                    if (original.GetParent().GetType() == typeof(labelObj))
                    {

                        classobj.addLabel(new labelObj());
                        labelObj label = classobj.getLabel(classobj.numlabels - 1);
                        MapUtils.SetDefaultLabel(label, layer.map);
                        label.insertStyle(((styleObj)original).clone(), -1);
                        style = label.getStyle(0);
                    }
                    else
                    {
                        classobj.insertStyle(((styleObj)original).clone(), -1);
                        style = classobj.getStyle(0);
                    }

                    // bindings are not supported with sample maps
                    StyleBindingController.RemoveAllBindings(style);
                    classobj.setText("Sample text");
                    this.target = new MapObjectHolder(style, original.GetParent());
                }
            }
            else if (original.GetType() == typeof(labelObj))
            {
                // tracking down the whole object tree
                originalClass = original.GetParent();
                if (originalClass != null)
                {
                    if (originalClass.GetType() == typeof(classObj))
                    {
                        originalLayer = originalClass.GetParent();
                        if (originalLayer != null)
                            originalMap = originalLayer.GetParent();
                    }
                    else if (originalClass.GetType() == typeof(scalebarObj))
                    {
                        originalMap = originalClass.GetParent();
                    }
                }

                // creating a new compatible map object
                if (originalMap != null)
                {
                    layerObj layer = InitializeDefaultLayer(originalMap, originalLayer);
                    classObj classobj = new classObj(layer);
                    classobj.name = MapUtils.GetClassName(layer);
                    labelObj label = new labelObj();

                    if (originalClass.GetType() == typeof(classObj))
                    {
                        // copy settings
                        label.updateFromString(((labelObj)original).convertToString());
                    }
                    classobj.addLabel(label);

                    this.target = new MapObjectHolder(layer.getClass(0).getLabel(0), original.GetParent());
                }
            }
            else
                throw new Exception("Invalid target type: " + original.GetType());
        }