Exemple #1
0
 public static void SetDefaultLabel(labelObj label, mapObj map)
 {
     label.size     = 8;
     label.force    = mapscript.MS_FALSE;
     label.partials = mapscript.MS_TRUE;
     label.position = (int)MS_POSITIONS_ENUM.MS_CC;
     // trying to set truetype fonts
     if (map != null)
     {
         string key     = null;
         string lastkey = null;
         while ((key = map.fontset.fonts.nextKey(key)) != null)
         {
             if (File.Exists(map.fontset.fonts.get(key, "")))
             {
                 lastkey = key;
                 if (string.Compare(key, "arial", true) == 0)
                 {
                     // set the default font to Arial if exists
                     break;
                 }
             }
         }
         if (lastkey != null)
         {
             label.font = lastkey;
             label.size = 8;
         }
     }
 }
Exemple #2
0
 public static void RemoveAllBindings(labelObj label)
 {
     for (int i = 0; i < mapscript.MS_LABEL_BINDING_LENGTH; i++)
     {
         label.removeBinding(i);
     }
 }
 internal static HandleRef getCPtrAndSetReference(labelObj obj, object parent) {
   if (obj != null)
   {
     obj.swigParentRef = parent;
     return obj.swigCPtr;
   }
   else
   {
     return new HandleRef(null, IntPtr.Zero);
   }
 }
Exemple #4
0
        /// <summary>
        /// Initialize the default settings of a newly created labelObj
        /// </summary>
        /// <param name="layer">The parent layer object.</param>
        public static void InitializeDefaultLabel(layerObj layer)
        {
            labelObj label;

            if (layer.getClass(0).numlabels == 0)
            {
                label = new labelObj();
                layer.getClass(0).addLabel(label);
            }
            label = layer.getClass(0).getLabel(0);
            SetDefaultLabel(label, layer.map);
        }
 internal static HandleRef getCPtrAndDisown(labelObj obj, object parent) {
   if (obj != null)
   {
     obj.swigCMemOwn = false;
     obj.swigParentRef = parent;
     return obj.swigCPtr;
   }
   else
   {
     return new HandleRef(null, IntPtr.Zero);
   }
 }
        /// <summary>
        /// Update the preview according to the current Editor state.
        /// In case of the preview a temporary object will only be updated.
        /// </summary>
        private void UpdatePreview()
        {
            labelObj style = mapControl.Target;

            if (style != null)
            {
                Update(style);
                if (style.getTextString() == null || style.getTextString() == "")
                {
                    style.setText("Sample Text");
                }
                style.setExpression("");
                mapControl.RefreshView();
            }
        }
Exemple #7
0
        public override void ApplyBinding()
        {
            if (target.GetParent().GetParent().GetType() != typeof(layerObj))
            {
                return;
            }

            labelObj label = target;

            if (BindingState)
            {
                label.setBinding((int)labelBinding, itemList.SelectedItem.ToString());
            }
            else
            {
                label.removeBinding((int)labelBinding);
            }
        }
 public static void RemoveAllBindings(labelObj label)
 {
     for (int i = 0; i < mapscript.MS_LABEL_BINDING_LENGTH; i++)
     {
         label.removeBinding(i);
     }
 }
        /// <summary>
        /// Update the label object according to the current Editor state.
        /// </summary>
        /// <param name="label">The object to be updated.</param>
        private void Update(labelObj label)
        {
            label.anglemode          = (MS_POSITIONS_ENUM)comboBoxAngleMode.SelectedItem;
            label.autominfeaturesize = checkBoxAutoMinFeatureSize.Checked ? mapscript.MS_TRUE : mapscript.MS_FALSE;
            label.partials           = checkBoxPartials.Checked ? mapscript.MS_TRUE : mapscript.MS_FALSE;
            label.force = checkBoxForce.Checked ? mapscript.MS_TRUE : mapscript.MS_FALSE;

            label.setExpression(this.textBoxExpression.Text);
            label.setText(this.textBoxText.Text);

            colorPickerColor.ApplyTo(label.color);
            colorPickerOutlineColor.ApplyTo(label.outlinecolor);
            colorPickerShadowColor.ApplyTo(label.shadowcolor);

            label.size        = int.Parse(textBoxSize.Text);
            label.minsize     = int.Parse(textBoxMinSize.Text);
            label.maxsize     = int.Parse(textBoxMaxSize.Text);
            label.mindistance = int.Parse(textBoxMinDistance.Text);
            label.offsetx     = int.Parse(textBoxOffsetX.Text);
            label.offsety     = int.Parse(textBoxOffsetY.Text);
            if (textBoxWrap.Text == "")
            {
                label.wrap = '\0';
            }
            else
            {
                label.wrap = Convert.ToChar(textBoxWrap.Text);
            }

            label.shadowsizex = int.Parse(textBoxShadowSizeX.Text);
            label.shadowsizey = int.Parse(textBoxShadowSizeY.Text);

            if (textBoxEncoding.Text == "")
            {
                label.encoding = null;
            }
            else
            {
                label.encoding = textBoxEncoding.Text;
            }
            label.angle = double.Parse(textBoxAngle.Text);

            label.position = (int)comboBoxPosition.SelectedItem;

            label.align = (int)comboBoxAlign.SelectedItem;

            if ((string)(comboBoxFont.SelectedItem) == "(none)")
            {
                label.font = null;
            }
            else
            {
                label.font = (string)(comboBoxFont.SelectedItem);
            }

            label.priority = int.Parse(textBoxPriority.Text);
            if (textBoxMaxScale.Text == "")
            {
                label.maxscaledenom = -1;
            }
            else
            {
                label.maxscaledenom = double.Parse(textBoxMaxScale.Text);
            }

            if (textBoxMinScale.Text == "")
            {
                label.minscaledenom = -1;
            }
            else
            {
                label.minscaledenom = double.Parse(textBoxMinScale.Text);
            }
            label.maxlength      = int.Parse(textBoxMaxLength.Text);
            label.minfeaturesize = int.Parse(textBoxMinFeatureSize.Text);
            label.buffer         = int.Parse(textBoxBuffer.Text);
            label.repeatdistance = int.Parse(textBoxRepeatDistance.Text);

            if (isStyleChanged)
            {
                // reconstruct styles
                while (label.numstyles > 0)
                {
                    label.removeStyle(0);
                }
                // insert styles in reverse order
                for (int i = listViewStyles.Items.Count - 1; i >= 0; --i)
                {
                    ListViewItem item  = listViewStyles.Items[i];
                    styleObj     style = (styleObj)item.Tag;
                    label.insertStyle(style.clone(), -1);
                }
            }
        }
 internal static HandleRef getCPtr(labelObj obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Exemple #11
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());
        }
Exemple #12
0
        public override void InitializeBinding(MapObjectHolder target)
        {
            this.target = target;

            if (target.GetParent().GetParent().GetType() != typeof(layerObj))
            {
                this.Enabled = false;
                return;
            }

            layerObj layer = target.GetParent().GetParent();
            labelObj label = target;

            if (itemList == null)
            {
                itemList                       = new ComboBox();
                itemList.Width                 = targetControl.Width;
                itemList.Height                = targetControl.Height;
                itemList.Location              = targetControl.Location;
                itemList.DropDownStyle         = ComboBoxStyle.DropDownList;
                itemList.SelectedIndexChanged += new EventHandler(itemList_SelectedIndexChanged);
                targetControl.Parent.Controls.Add(itemList);
                itemList.BringToFront();
                Bitmap bmp = Resources.DataConnection;
                bmp.MakeTransparent(Color.Magenta);
                pbox          = new PictureBox();
                pbox.Image    = bmp;
                pbox.SizeMode = PictureBoxSizeMode.AutoSize;
                pbox.Location = new System.Drawing.Point(targetControl.Location.X + targetControl.Width + 2,
                                                         targetControl.Location.Y + (targetControl.Height - pbox.Image.Height) / 2);
                targetControl.Parent.Controls.Add(pbox);
                pbox.BringToFront();
            }

            BindingState = false;

            itemList.Items.Clear();
            layer.open();
            for (int i = 0; i < layer.numitems; i++)
            {
                itemList.Items.Add(layer.getItem(i));
            }
            if (layer.getResults() == null)
            {
                layer.close(); // close only is no query results
            }
            if (layer.connectiontype == MS_CONNECTION_TYPE.MS_OGR)
            {
                itemList.Items.Add("OGR:LabelFont");
                itemList.Items.Add("OGR:LabelSize");
                itemList.Items.Add("OGR:LabelText");
                itemList.Items.Add("OGR:LabelAngle");
                itemList.Items.Add("OGR:LabelFColor");
                itemList.Items.Add("OGR:LabelBColor");
                itemList.Items.Add("OGR:LabelPlacement");
                itemList.Items.Add("OGR:LabelAnchor");
                itemList.Items.Add("OGR:LabelDx");
                itemList.Items.Add("OGR:LabelDy");
                itemList.Items.Add("OGR:LabelPerp");
                itemList.Items.Add("OGR:LabelBold");
                itemList.Items.Add("OGR:LabelItalic");
                itemList.Items.Add("OGR:LabelUnderline");
                itemList.Items.Add("OGR:LabelPriority");
                itemList.Items.Add("OGR:LabelStrikeout");
                itemList.Items.Add("OGR:LabelStretch");
                itemList.Items.Add("OGR:LabelAdjHor");
                itemList.Items.Add("OGR:LabelAdjVert");
                itemList.Items.Add("OGR:LabelHColor");
                itemList.Items.Add("OGR:LabelOColor");
            }

            string binding = label.getBinding((int)labelBinding);

            if (binding != null)
            {
                itemList.SelectedItem = binding;
                BindingState          = true;
            }
            else
            {
                if (itemList.Items.Count > 0)
                {
                    itemList.SelectedIndex = 0;
                }
            }
        }
Exemple #13
0
 public static void SetDefaultLabel(labelObj label, mapObj map)
 {
     label.type = MS_FONT_TYPE.MS_BITMAP;
     label.size = (int)MS_BITMAP_FONT_SIZES.MS_MEDIUM;
     label.force = mapscript.MS_FALSE;
     label.partials = mapscript.MS_TRUE;
     label.position = (int)MS_POSITIONS_ENUM.MS_CC;
     // trying to set truetype fonts
     if (map != null)
     {
         string key = null;
         string lastkey = null;
         while ((key = map.fontset.fonts.nextKey(key)) != null)
         {
             if (File.Exists(map.fontset.fonts.get(key, "")))
             {
                 lastkey = key;
                 if (string.Compare(key, "arial", true) == 0)
                 {
                     // set the default font to Arial if exists
                     break;
                 }
             }
         }
         if (lastkey != null)
         {
             label.font = lastkey;
             label.type = MS_FONT_TYPE.MS_TRUETYPE;
             label.size = 8;
         }
     }
 }
Exemple #14
0
 /// <summary>
 /// Initialize the default settings of a newly created labelObj
 /// </summary>
 /// <param name="layer">The parent layer object.</param>
 public static void InitializeDefaultLabel(layerObj layer)
 {
     labelObj label;
     if (layer.getClass(0).numlabels == 0)
     {
         label = new labelObj();
         layer.getClass(0).addLabel(label);
     }
     label = layer.getClass(0).getLabel(0);
     SetDefaultLabel(label, layer.map);
 }
        /// <summary>
        /// Update the label object according to the current Editor state.
        /// </summary>
        /// <param name="label">The object to be updated.</param>
        private void Update(labelObj label)
        {
            label.anglemode = (int)comboBoxAngleMode.SelectedItem;
            label.autominfeaturesize = checkBoxAutoMinFeatureSize.Checked ? mapscript.MS_TRUE : mapscript.MS_FALSE;
            label.partials = checkBoxPartials.Checked ? mapscript.MS_TRUE : mapscript.MS_FALSE;
            label.force = checkBoxForce.Checked ? mapscript.MS_TRUE : mapscript.MS_FALSE;

            label.setExpression(this.textBoxExpression.Text);
            label.setText(this.textBoxText.Text);

            colorPickerColor.ApplyTo(label.color);
            colorPickerOutlineColor.ApplyTo(label.outlinecolor);
            colorPickerShadowColor.ApplyTo(label.shadowcolor);

            label.type = MS_FONT_TYPE.MS_TRUETYPE;
            label.size = double.Parse(textBoxSize.Text);
            label.minsize = double.Parse(textBoxMinSize.Text);
            label.maxsize = double.Parse(textBoxMaxSize.Text);
            label.mindistance = int.Parse(textBoxMinDistance.Text);
            label.offsetx = int.Parse(textBoxOffsetX.Text);
            label.offsety = int.Parse(textBoxOffsetY.Text);
            if (textBoxWrap.Text == "")
                label.wrap = '\0';
            else
                label.wrap = Convert.ToChar(textBoxWrap.Text);

            label.shadowsizex = int.Parse(textBoxShadowSizeX.Text);
            label.shadowsizey = int.Parse(textBoxShadowSizeY.Text);

            if (textBoxEncoding.Text == "")
                label.encoding = null;
            else
                label.encoding = textBoxEncoding.Text;
            label.angle = double.Parse(textBoxAngle.Text);

            label.position = (int)comboBoxPosition.SelectedItem;

            label.align = (int)comboBoxAlign.SelectedItem;

            if ((string)(comboBoxFont.SelectedItem) == "(none)")
                label.font = null;
            else
                label.font = (string)(comboBoxFont.SelectedItem);

            label.priority = int.Parse(textBoxPriority.Text);
            if (textBoxMaxScale.Text == "")
                label.maxscaledenom = -1;
            else
                label.maxscaledenom = double.Parse(textBoxMaxScale.Text);

            if (textBoxMinScale.Text == "")
                label.minscaledenom = -1;
            else
                label.minscaledenom = double.Parse(textBoxMinScale.Text);
            label.maxlength = int.Parse(textBoxMaxLength.Text);
            label.minfeaturesize = int.Parse(textBoxMinFeatureSize.Text);
            label.buffer = int.Parse(textBoxBuffer.Text);
            label.repeatdistance = int.Parse(textBoxRepeatDistance.Text);

            if (isStyleChanged)
            {
                // reconstruct styles
                while (label.numstyles > 0)
                    label.removeStyle(0);
                // insert styles in reverse order
                for (int i = listViewStyles.Items.Count - 1; i >= 0; --i)
                {
                    ListViewItem item = listViewStyles.Items[i];
                    styleObj style = (styleObj)item.Tag;
                    label.insertStyle(style.clone(), -1);
                }
            }
        }
Exemple #16
0
 public LabelEditorDialog(classObj inClass)
 {
     InitializeComponent();
     m_pLabel = inClass.label;
     m_pClass = inClass;
 }
Exemple #17
0
        /// <summary>
        /// show the labelobj's value
        /// </summary>
        /// <param name="label"></param>
        /// <returns></returns>
        private bool InitializeLabel(labelObj label)
        {
            if (label == null) return false;

            try
            {
                //read the angle info of the label
                if (label.autoangle != 0)
                    comboBoxAngle.Text = "auto";
                else if (label.autofollow != 0)
                    comboBoxAngle.Text = "follow";
                else
                    comboBoxAngle.Text = label.angle.ToString();

                //color info
                ButtonColor.ButtonColor =
                    Color.FromArgb(label.color.red, label.color.green, label.color.blue);

                //size info
                if (label.size == -1)
                    checkBoxShowLabel.Checked = false;
                else
                    checkBoxShowLabel.Checked = true;

                numericUpDownSize.Value = (decimal)label.size;

                //max and min size
                numericUpDownMaxSize.Value = (decimal)label.maxsize;
                numericUpDownMinSize.Value = (decimal)label.minsize;

                //position
                string strPosition = ((MS_POSITIONS_ENUM)label.position).ToString();
                if (strPosition.Length > 0)
                {
                    string[] strValues = strPosition.Split('_');
                    if (strValues.Length == 2)
                        comboBoxPosition.SelectedIndex = comboBoxPosition.FindString(strValues[1]);
                }

                //mindistance
                numericUpDownMinDist.Value = (decimal)label.mindistance;

                //antialias
                comboBoxAntiAlias.SelectedIndex = label.antialias;

                //partials
                comboBoxPartials.SelectedIndex = label.partials;

                //encoding
                textBoxEncoding.Text = label.encoding;

                //font
                if (label.font != null)
                {
                    comboBoxFont.SelectedIndex = comboBoxFont.FindString(label.font);
                }

                //font type
                if (label.type == MS_FONT_TYPE.MS_BITMAP)
                    comboBoxType.SelectedIndex = 0;
                else if (label.type == MS_FONT_TYPE.MS_TRUETYPE)
                    comboBoxType.SelectedIndex = 1;

                //align
                string sAlign = ((MS_ALIGN_VALUE)label.align).ToString();
                string[] sAligns = sAlign.Split('_');
                if (sAligns.Length == 3)
                {
                    comboBoxAlign.SelectedIndex = comboBoxAlign.FindString(sAligns[2]);
                }

                //wrap
                textBoxWarp.Text = label.wrap.ToString();

                //maxlength
                numericUpDownMaxLength.Value = (decimal)label.maxlength;

                //force
                comboBoxForce.SelectedIndex = label.force;

                //priority
                comboBoxPriority.SelectedIndex = label.priority - 1;

                //minfeaturesize
                if (label.autominfeaturesize != 0)
                {
                    comboBoxMinFeatureSize.SelectedIndex = 0;
                }
                else
                    comboBoxMinFeatureSize.Text = label.minfeaturesize.ToString();

                //buffer
                numericUpDownBuffer.Value = (decimal)label.buffer;

                //shadow color
                if ((label.shadowcolor.red == -1) || (label.shadowcolor.green == -1) ||
                    (label.shadowcolor.blue == -1))
                {
                    ButtonShadowColor.ButtonColor = Color.Transparent;
                }
                else
                {
                    ButtonShadowColor.ButtonColor =
            Color.FromArgb(label.shadowcolor.red, label.shadowcolor.green, label.shadowcolor.blue);

                }

                //shadow size
                numericUpDownShadowSizeX.Value = (decimal)label.shadowsizex;
                numericUpDownShadowSizeY.Value = (decimal)label.shadowsizey;

                //outline color
                if ((label.outlinecolor.red == -1) || (label.outlinecolor.green == -1) ||
                    (label.outlinecolor.blue == -1))
                {
                    ButtonOutLineColor.ButtonColor = Color.Transparent;
                }
                else
                {
                    ButtonOutLineColor.ButtonColor =
            Color.FromArgb(label.outlinecolor.red, label.outlinecolor.green, label.outlinecolor.blue);

                }

                //outline width
                numericUpDownOutlineWidth.Value = (decimal)label.outlinewidth;

                //backgorundcolor color
                if ((label.backgroundcolor.red == -1) || (label.backgroundcolor.green == -1) ||
                    (label.backgroundcolor.blue == -1))
                {
                    ButtonBGColor.ButtonColor = Color.Transparent;
                }
                else
                {
                    ButtonBGColor.ButtonColor =
            Color.FromArgb(label.backgroundcolor.red, label.backgroundcolor.green, label.backgroundcolor.blue);

                }

                //backgorundshadowcolor color
                if ((label.backgroundshadowcolor.red == -1) || (label.backgroundshadowcolor.green == -1) ||
                    (label.backgroundshadowcolor.blue == -1))
                {
                    ButtonBGSColor.ButtonColor = Color.Transparent;
                }
                else
                {
                    ButtonBGSColor.ButtonColor =
            Color.FromArgb(label.backgroundshadowcolor.red, label.backgroundshadowcolor.green, label.backgroundshadowcolor.blue);

                }

                //backgroundshadowsize
                numericUpDownBGSSizeX.Value = (decimal)label.backgroundshadowsizex;
                numericUpDownBGSSizeY.Value = (decimal)label.backgroundshadowsizey;

            }
            catch(Exception ex)
            {
                Utility.PostWarning(ex.Message);
            }

            return true;
        }