Пример #1
0
        /// <summary>
        /// Update the preview according to the changes
        /// </summary>
        private void UpdatePreview()
        {
            if (style != null && enablePreview)
            {
                styleObj pstyle = style.clone();
                Update(pstyle);

                classObj styleclass = new classObj(null);
                styleclass.insertStyle(pstyle, -1);

                using (classObj def_class = new classObj(null)) // for drawing legend images
                {
                    using (imageObj image2 = def_class.createLegendIcon(
                               map, layer, pictureBoxPreview.Width, pictureBoxPreview.Height))
                    {
                        styleclass.drawLegendIcon(map, layer,
                                                  pictureBoxPreview.Width - 10, pictureBoxPreview.Height - 10, image2, 4, 4);
                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxPreview.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
            else
            {
                pictureBoxPreview.Image = null;
            }
        }
Пример #2
0
        /// <summary>
        /// Update the list item according to a modified style
        /// </summary>
        /// <param name="index">the index of the lit item</param>
        /// <param name="style">the style object</param>
        private void UpdateStyleInList(int index)
        {
            layerObj layer;

            if (target.GetParent().GetType() == typeof(scalebarObj))
            {
                layer = new layerObj(null);
            }
            else
            {
                layer = target.GetParent().GetParent();
            }

            ListViewItem item  = listViewStyles.Items[index];
            styleObj     style = (styleObj)item.Tag;

            classObj styleclass = new classObj(null);

            styleclass.insertStyle(style, -1);
            // creating the list icon
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(map, layer, 30, 20))
                {
                    MS_LAYER_TYPE type = layer.type;
                    try
                    {
                        // modify the layer type in certain cases for drawing correct images
                        string geomtransform = style.getGeomTransform().ToLower();
                        if (geomtransform != null)
                        {
                            if (geomtransform.Contains("labelpoly"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            }
                            else if (geomtransform.Contains("labelpnt"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                            }
                        }
                        styleclass.drawLegendIcon(map, layer, 20, 10, image2, 5, 5);
                    }
                    finally
                    {
                        layer.type = type;
                    }

                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images[item.ImageIndex] = Image.FromStream(ms);
                    }


                    item.SubItems[1].Text = style.size.ToString();
                    item.SubItems[2].Text = style.width.ToString();
                    item.SubItems[3].Text = style.symbolname;
                }
            }
        }
Пример #3
0
    public void testRemoveStyleObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj classobj = layer.getClass(0);
        styleObj newStyle = new styleObj(null);

        classobj.insertStyle(newStyle, 0);
        classobj.removeStyle(0);

        map = null; layer = null; classobj = null;
        gc();
        assert(newStyle.refcount == 1, "testRemoveStyleObj");
    }
Пример #4
0
    public void testInsertStyleObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj classobj = layer.getClass(0);
        styleObj newStyle = new styleObj(null);

        classobj.insertStyle(newStyle, -1);

        assert(newStyle.refcount == 2, "testInsertStyleObj precondition");
        map = null; layer = null; classobj = null;
        gc();
        assert(newStyle.refcount == 2, "testInsertStyleObj");
    }
Пример #5
0
        private ListViewItem AddListItem(styleObj classStyle, layerObj layer, string name)
        {
            ListViewItem item       = null;
            classObj     styleclass = new classObj(null);

            styleclass.insertStyle(classStyle, -1);
            mapObj map2 = map;

            if (layer.map != null)
            {
                map2 = layer.map;
            }
            // creating the listicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(
                           map2, layer, imageList.ImageSize.Width, imageList.ImageSize.Height))
                {
                    MS_LAYER_TYPE type = layer.type;
                    try
                    {
                        //SETPH: actually we should not modify the type of the style(point line polygon) for the style category list, only for the preview
                        //// modify the layer type in certain cases for drawing correct images
                        //if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly"))
                        //layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                        //else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt"))
                        //layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;

                        styleclass.drawLegendIcon(map2, layer, 44, 44, image2, 2, 2);
                    }
                    finally
                    {
                        layer.type = type;
                    }
                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    // add new item
                    item             = new ListViewItem(name, imageList.Images.Count - 1);
                    item.ToolTipText = name;
                    item.Tag         = classStyle;
                    listView.Items.Add(item);
                }
            }
            return(item);
        }
Пример #6
0
    public void testInsertStyleObjDestroy()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj classobj = layer.getClass(0);
        styleObj newStyle = new styleObj(null);

        classobj.insertStyle(newStyle, 0);
        styleObj reference = classobj.getStyle(0);

        assert(newStyle.refcount == 3, "testInsertStyleObjDestroy precondition");
        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, "testInsertStyleObjDestroy");
    }
Пример #7
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());
        }
Пример #8
0
        private void UpdatePreview()
        {
            if (style != null && enablePreview)
            {
                styleObj pstyle = style.clone();
                Update(pstyle);

                // apply current settings (opacity) to colors
                colorPickerColor.SetColor(pstyle.color);
                colorPickerBackColor.SetColor(pstyle.backgroundcolor);
                colorPickerOutlineColor.SetColor(pstyle.outlinecolor);

                // select the proper map containing symbols
                mapObj stylemap = map;
                if (listView.SelectedItems.Count > 0 && listView.SelectedItems[0].Text != "Default")
                {
                    if (comboBoxCategory.Text != "Inline Symbols")
                    {
                        stylemap = StyleLibrary.Styles;
                    }
                    styleObj classStyle = (styleObj)listView.SelectedItems[0].Tag;
                    pstyle.setSymbolByName(stylemap, classStyle.symbolname);
                }
                else
                {
                    pstyle.symbol     = 0;
                    pstyle.symbolname = null;
                }

                classObj styleclass = new classObj(null);
                styleclass.insertStyle(pstyle, -1);

                using (classObj def_class = new classObj(null)) // for drawing legend images
                {
                    using (imageObj image2 = def_class.createLegendIcon(
                               stylemap, layer, pictureBoxSample.Width, pictureBoxSample.Height))
                    {
                        MS_LAYER_TYPE type = layer.type;
                        try
                        {
                            // modify the layer type in certain cases for drawing correct images
                            if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            }
                            else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt") || comboBoxGeomTransform.Text.ToLower().Contains("centroid"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                            }

                            styleclass.drawLegendIcon(stylemap, layer,
                                                      pictureBoxSample.Width - 10, pictureBoxSample.Height - 10, image2, 4, 4);
                        }
                        finally
                        {
                            layer.type = type;
                        }

                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxSample.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
        }
Пример #9
0
        private void UpdatePreview()
        {
            if (style != null && enablePreview)
            {
                styleObj pstyle = style.clone();
                Update(pstyle);

                // apply current settings (opacity) to colors
                colorPickerColor.SetColor(pstyle.color);
                colorPickerBackColor.SetColor(pstyle.backgroundcolor);
                colorPickerOutlineColor.SetColor(pstyle.outlinecolor);

                // select the proper map containing symbols
                mapObj stylemap = map;
                if (listView.SelectedItems.Count > 0 && listView.SelectedItems[0].Text != "Default")
                {
                    if (comboBoxCategory.Text != "Inline Symbols")
                        stylemap = StyleLibrary.Styles;
                    styleObj classStyle = (styleObj)listView.SelectedItems[0].Tag;
                    pstyle.setSymbolByName(stylemap, classStyle.symbolname);
                }
                else
                {
                    pstyle.symbol = 0;
                    pstyle.symbolname = null;
                }

                classObj styleclass = new classObj(null);
                styleclass.insertStyle(pstyle, -1);

                using (classObj def_class = new classObj(null)) // for drawing legend images
                {
                    using (imageObj image2 = def_class.createLegendIcon(
                                     stylemap, layer, pictureBoxSample.Width, pictureBoxSample.Height))
                    {
                        MS_LAYER_TYPE type = layer.type;
                        try
                        {
                            // modify the layer type in certain cases for drawing correct images
                            if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly"))
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt") || comboBoxGeomTransform.Text.ToLower().Contains("centroid"))
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;

                            styleclass.drawLegendIcon(stylemap, layer,
                            pictureBoxSample.Width - 10, pictureBoxSample.Height - 10, image2, 4, 4);
                        }
                        finally
                        {
                            layer.type = type;
                        }

                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxSample.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
        }
Пример #10
0
        private ListViewItem AddListItem(styleObj classStyle, layerObj layer, string name)
        {
            ListViewItem item = null;
            classObj styleclass = new classObj(null);
            styleclass.insertStyle(classStyle, -1);
            mapObj map2 = map;
            if (layer.map != null)
                map2 = layer.map;
            // creating the listicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(
                                 map2, layer, imageList.ImageSize.Width, imageList.ImageSize.Height))
                {
                    MS_LAYER_TYPE type = layer.type;
                    try
                    {
                        //SETPH: actually we should not modify the type of the style(point line polygon) for the style category list, only for the preview
                        //// modify the layer type in certain cases for drawing correct images
                        //if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly"))
                            //layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                        //else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt"))
                            //layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;

                        styleclass.drawLegendIcon(map2, layer, 44, 44, image2, 2, 2);
                    }
                    finally
                    {
                        layer.type = type;
                    }
                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    // add new item
                    item = new ListViewItem(name, imageList.Images.Count - 1);
                    item.ToolTipText = name;
                    item.Tag = classStyle;
                    listView.Items.Add(item);
                }
            }
            return item;
        }
Пример #11
0
        /// <summary>
        /// Adding a new styleObj to the corresponding classObj.
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection of the parent object</param>
        /// <param name="styleHolder">Wrapper class containing the styleObj and the parent object</param>
        /// /// <param name="showRoot">A flag indicating whether the root object should be displayed or not.</param>
        private void AddStyleNode(TreeNodeCollection nodes, MapObjectHolder styleHolder, ImageList imageList)
        {
            layerObj layer = styleHolder.GetParent().GetParent();
            classObj layerclass = styleHolder.GetParent();
            styleObj classStyle = styleHolder;

            classObj styleclass = new classObj(null);
            styleclass.name = MapUtils.GetClassName(layer);
            styleclass.insertStyle(classStyle, -1);
            // creating the treeicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(
                                 map, layer, legendIconSize.Width, legendIconSize.Height))
                {
                    styleclass.drawLegendIcon(map, layer,
                        legendDrawingSize.Width, legendDrawingSize.Height, image2,
                        LegendIconPadding.Left, LegendIconPadding.Top);
                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    TreeNode styleNode = new TreeNode("Style (" + nodes.Count + ")",
                        imageList.Images.Count - 1, imageList.Images.Count - 1);
                    styleNode.Tag = styleHolder;
                    styleNode.Checked = true;
                    nodes.Add(styleNode);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Update the list item according to a modified style
        /// </summary>
        /// <param name="index">the index of the lit item</param>
        /// <param name="style">the style object</param>
        private void UpdateStyleInList(int index)
        {
            layerObj layer;
            if (target.GetParent().GetType() == typeof(scalebarObj))
                layer = new layerObj(null);
            else
                layer = target.GetParent().GetParent();

            ListViewItem item = listViewStyles.Items[index];
            styleObj style = (styleObj)item.Tag;

            classObj styleclass = new classObj(null);
            styleclass.insertStyle(style, -1);
            // creating the list icon
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(map, layer, 30, 20))
                {
                    MS_LAYER_TYPE type = layer.type;
                    try
                    {
                        // modify the layer type in certain cases for drawing correct images
                        string geomtransform = style.getGeomTransform().ToLower();
                        if (geomtransform != null)
                        {
                            if (geomtransform.Contains("labelpoly"))
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            else if (geomtransform.Contains("labelpnt"))
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                        }
                        styleclass.drawLegendIcon(map, layer, 20, 10, image2, 5, 5);
                    }
                    finally
                    {
                        layer.type = type;
                    }

                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images[item.ImageIndex] = Image.FromStream(ms);
                    }

                    item.SubItems[1].Text = style.size.ToString();
                    item.SubItems[2].Text = style.width.ToString();
                    item.SubItems[3].Text = style.symbolname;
                }
            }
        }
        /// <summary>
        /// Update the preview according to the changes
        /// </summary>
        private void UpdatePreview()
        {
            if (style != null && enablePreview)
            {
                styleObj pstyle = style.clone();
                Update(pstyle);

                classObj styleclass = new classObj(null);
                styleclass.insertStyle(pstyle, -1);

                using (classObj def_class = new classObj(null)) // for drawing legend images
                {
                    using (imageObj image2 = def_class.createLegendIcon(
                                     map, layer, pictureBoxPreview.Width, pictureBoxPreview.Height))
                    {
                        styleclass.drawLegendIcon(map, layer,
                            pictureBoxPreview.Width - 10, pictureBoxPreview.Height - 10, image2, 4, 4);
                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxPreview.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
            else
                pictureBoxPreview.Image = null;
        }