internal static HandleRef getCPtrAndSetReference(symbolObj obj, object parent) {
   if (obj != null)
   {
     obj.swigParentRef = parent;
     return obj.swigCPtr;
   }
   else
   {
     return new HandleRef(null, IntPtr.Zero);
   }
 }
 internal static HandleRef getCPtrAndDisown(symbolObj obj, object parent) {
   if (obj != null)
   {
     obj.swigCMemOwn = false;
     obj.swigParentRef = parent;
     return obj.swigCPtr;
   }
   else
   {
     return new HandleRef(null, IntPtr.Zero);
   }
 }
Example #3
0
 /// <summary>
 /// Find symbol by name (without adding)
 /// </summary>
 /// <param name="symbolset">The symbolset object</param>
 /// <param name="key_to_find">the symbol name to search for</param>
 /// <returns>Symbol found or null</returns>
 public static symbolObj FindSymbol(symbolSetObj symbolset, string name_to_find)
 {
     if (name_to_find != null)
     {
         for (int i = 0; i < symbolset.numsymbols; i++)
         {
             symbolObj sym = symbolset.getSymbol(i);
             if (sym.name != null && sym.name.ToLower() == name_to_find.ToLower())
             {
                 return(sym);
             }
         }
     }
     return(null);
 }
Example #4
0
        public static symbolObj CloneSymbol(symbolObj origsym)
        {
            symbolObj sym = new symbolObj(origsym.name, origsym.imagepath);

            sym.anchorpoint_x    = origsym.anchorpoint_x;
            sym.anchorpoint_y    = origsym.anchorpoint_y;
            sym.type             = origsym.type;
            sym.font             = origsym.font;
            sym.filled           = origsym.filled;
            sym.character        = origsym.character;
            sym.transparent      = origsym.transparent;
            sym.transparentcolor = origsym.transparentcolor;
            sym.setPoints(origsym.getPoints());
            sym.sizex     = origsym.sizex;
            sym.sizey     = origsym.sizey;
            sym.inmapfile = origsym.inmapfile;
            return(sym);
        }
Example #5
0
 public static symbolObj CloneSymbol(symbolObj origsym)
 {
     symbolObj sym = new symbolObj(origsym.name, origsym.imagepath);
     sym.anchorpoint_x = origsym.anchorpoint_x;
     sym.anchorpoint_y = origsym.anchorpoint_y;
     sym.type = origsym.type;
     sym.font = origsym.font;
     sym.filled = origsym.filled;
     sym.character = origsym.character;
     sym.antialias = origsym.antialias;
     sym.transparent = origsym.transparent;
     sym.transparentcolor = origsym.transparentcolor;
     sym.setPoints(origsym.getPoints());
     sym.sizex = origsym.sizex;
     sym.sizey = origsym.sizey;
     sym.inmapfile = origsym.inmapfile;
     return sym;
 }
Example #6
0
 /// <summary>
 /// Click event handler of the buttonRemoveFont control.
 /// </summary>
 /// <param name="sender">The source object of this event.</param>
 /// <param name="layer">The selected layer.</param>
 private void buttonRemoveFont_Click(object sender, EventArgs e)
 {
     if (listViewFonts.SelectedItems.Count > 0)
     {
         // check whether we have symbol references to this font
         string fontName = listViewFonts.SelectedItems[0].Text;
         if (map != null)
         {
             symbolSetObj symbolset = map.symbolset;
             for (int i = 0; i < symbolset.numsymbols; i++)
             {
                 symbolObj sym = map.symbolset.getSymbol(i);
                 if (String.Compare(sym.font, fontName, true) == 0)
                 {
                     MessageBox.Show("Unable to remove the selected font! The map file contains symbol referring to this font: " + sym.name, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     return;
                 }
             }
         }
         if (StyleLibrary.Styles != null)
         {
             symbolSetObj symbolset = ((mapObj)StyleLibrary.Styles).symbolset;
             for (int i = 0; i < symbolset.numsymbols; i++)
             {
                 symbolObj sym = map.symbolset.getSymbol(i);
                 if (String.Compare(sym.font, fontName, true) == 0)
                 {
                     MessageBox.Show("Unable to remove the selected font! The style library contains symbol referring to this font: " + sym.name, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     return;
                 }
             }
         }
         if (MessageBox.Show("Are you sure you want to delete the selected font?",
                             "MapManager", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
         {
             return;
         }
         listViewFonts.Items.Remove(listViewFonts.SelectedItems[0]);
         SetFontsetModified(true);
     }
 }
Example #7
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());
            }
        }
Example #8
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;
                }
            }
        }
        /// <summary>
        /// Create the theme according to the individual values of the layer contents
        /// </summary>
        private MapObjectHolder CreateLayerTheme()
        {
            if (layer == null)
            {
                return(null);
            }

            mapObj map = target.GetParent();

            // create a new map object
            mapObj newMap = new mapObj(null);

            newMap.units = MS_UNITS.MS_PIXELS;
            map.selectOutputFormat(map.imagetype);
            // copy symbolset
            for (int s = 1; s < map.symbolset.numsymbols; s++)
            {
                symbolObj origsym = map.symbolset.getSymbol(s);
                newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym));
            }
            // copy the fontset
            string key = null;

            while ((key = map.fontset.fonts.nextKey(key)) != null)
            {
                newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, ""));
            }

            newLayer                = new layerObj(newMap);
            newLayer.type           = layer.type;
            newLayer.status         = mapscript.MS_ON;
            newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
            // add the classObj and styles
            classObj classobj;

            if (checkBoxKeepStyles.Checked)
            {
                classobj = layer.getClass(0).clone();
                classobj.setExpression(""); // remove expression to have the class shown
                // 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));
                }
                newLayer.insertClass(classobj, -1);
            }
            else
            {
                classobj      = new classObj(newLayer);
                classobj.name = MapUtils.GetClassName(newLayer);
                styleObj style = new styleObj(classobj);
                style.size = 8; // set default size (#4339)

                if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    // initialize with the default marker if specified in the symbol file for point symbols
                    symbolObj symbol;
                    for (int s = 0; s < map.symbolset.numsymbols; s++)
                    {
                        symbol = map.symbolset.getSymbol(s);

                        if (symbol.name == "default-marker")
                        {
                            style.symbol     = s;
                            style.symbolname = "default-marker";
                            break;
                        }
                    }
                }
                MapUtils.SetDefaultColor(layer.type, style);
            }

            SortedDictionary <string, string> items = new SortedDictionary <string, string>();
            int i = 0;

            shapeObj shape;

            layer.open();

            layer.whichShapes(layer.getExtent());

            if (checkBoxClassItem.Checked)
            {
                layer.classitem = comboBoxColumns.SelectedItem.ToString();
            }

            while ((shape = layer.nextShape()) != null)
            {
                string value = shape.getValue(comboBoxColumns.SelectedIndex);
                if (checkBoxZero.Checked && (value == "" || value == ""))
                {
                    continue;
                }

                if (!items.ContainsValue(value))
                {
                    if (i == 100)
                    {
                        if (MessageBox.Show("The number of the individual values is greater than 100 would you like to continue?", "MapManager",
                                            MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
                        {
                            break;
                        }
                    }

                    items.Add(value, value);

                    ++i;
                }
            }

            if (layer.getResults() == null)
            {
                layer.close(); // close only is no query results
            }
            i = 0;
            foreach (string value in items.Keys)
            {
                double percent = ((double)(i + 1)) / items.Count * 100;

                // creating the corresponding class object
                if (i > 0)
                {
                    classobj = classobj.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));
                    }
                    newLayer.insertClass(classobj, -1);
                }

                classobj.name = value;
                if (checkBoxClassItem.Checked)
                {
                    classobj.setExpression(value);
                }
                else
                {
                    classobj.setExpression("('[" + comboBoxColumns.SelectedItem + "]' = '" + value + "')");
                }

                for (int j = 0; j < classobj.numstyles; j++)
                {
                    styleObj style = classobj.getStyle(j);
                    style.color           = colorRampPickerColor.GetMapColorAtValue(percent);
                    style.outlinecolor    = colorRampPickerOutlineColor.GetMapColorAtValue(percent);
                    style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent);

                    if (checkBoxFirstOnly.Checked)
                    {
                        break;
                    }
                }
                ++i;
            }

            return(new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null)));
        }
Example #10
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);
        }
Example #11
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();
            }
        }
 public int appendSymbol(symbolObj symbol) {
   int ret = mapscriptPINVOKE.symbolSetObj_appendSymbol(swigCPtr, symbolObj.getCPtr(symbol));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Example #13
0
        /// <summary>
        /// Create the theme according to the individual values of the layer contents
        /// </summary>
        private MapObjectHolder CreateLayerTheme()
        {
            if (layer == null)
            {
                return(null);
            }

            int index;

            for (index = 0; index < fieldName.Length; index++)
            {
                if (fieldName[index] == comboBoxColumns.Text)
                {
                    break;
                }
            }
            if (index == fieldName.Length)
            {
                return(null);
            }

            NumberFormatInfo ni = new NumberFormatInfo();

            ni.NumberDecimalSeparator = ".";
            mapObj map = target.GetParent();

            // create a new map object
            mapObj newMap = new mapObj(null);

            newMap.units = MS_UNITS.MS_PIXELS;
            map.selectOutputFormat(map.imagetype);
            // copy symbolset
            for (int s = 1; s < map.symbolset.numsymbols; s++)
            {
                symbolObj origsym = map.symbolset.getSymbol(s);
                newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym));
            }
            // copy the fontset
            string key = null;

            while ((key = map.fontset.fonts.nextKey(key)) != null)
            {
                newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, ""));
            }

            newLayer                = new layerObj(newMap);
            newLayer.type           = layer.type;
            newLayer.status         = mapscript.MS_ON;
            newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
            // add the classObj and styles
            classObj classobj;

            if (checkBoxKeepStyles.Checked)
            {
                classobj = layer.getClass(0).clone();
                classobj.setExpression(""); // remove expression to have the class shown
                // 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));
                }
                newLayer.insertClass(classobj, -1);
            }
            else
            {
                classobj      = new classObj(newLayer);
                classobj.name = MapUtils.GetClassName(newLayer);
                styleObj style = new styleObj(classobj);
                style.size = 8; // set default size (#4339)

                if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    // initialize with the default marker if specified in the symbol file for point symbols
                    symbolObj symbol;
                    for (int s = 0; s < map.symbolset.numsymbols; s++)
                    {
                        symbol = map.symbolset.getSymbol(s);

                        if (symbol.name == "default-marker")
                        {
                            style.symbol     = s;
                            style.symbolname = "default-marker";
                            break;
                        }
                    }
                }
                MapUtils.SetDefaultColor(layer.type, style);
            }

            // calculate breaks
            int classes = (int)numericUpDownClasses.Value;

            double[] breaks = null;
            if (comboBoxMode.SelectedIndex == 0)
            {
                breaks = CalculateEqualInterval(classes, index);
            }

            if (breaks == null)
            {
                return(null);
            }

            for (int i = 0; i < classes; i++)
            {
                double percent = ((double)(i + 1)) / classes * 100;
                // creating the corresponding class object
                if (i > 0)
                {
                    classobj = classobj.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));
                    }
                    newLayer.insertClass(classobj, -1);
                }

                classobj.name = breaks[i].ToString(ni) + " - " + breaks[i + 1].ToString(ni);
                classobj.setExpression("(([" + comboBoxColumns.SelectedItem + "] >= "
                                       + breaks[i].ToString(ni) + ") && ([" + comboBoxColumns.SelectedItem + "] <= "
                                       + breaks[i + 1].ToString(ni) + "))");
                for (int j = 0; j < classobj.numstyles; j++)
                {
                    styleObj style = classobj.getStyle(j);
                    style.color           = colorRampPickerColor.GetMapColorAtValue(percent);
                    style.outlinecolor    = colorRampPickerOutlineColor.GetMapColorAtValue(percent);
                    style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent);

                    if (checkBoxFirstOnly.Checked)
                    {
                        break;
                    }
                }
            }

            return(new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null)));
        }
Example #14
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());
            }
        }
 internal static HandleRef getCPtr(symbolObj obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }