Ejemplo n.º 1
0
 bool Equals(PgStyleObjectM obj)
 {
     if (obj == null)
     {
         return(false);
     }
     return(this.Table == obj.Table &&
            this.IdObject.Equals(obj.IdObject));
 }
Ejemplo n.º 2
0
 public PgAttributesStyleVM(PgAtVM.PgAttributesVM attributeVM)
 {
     _attributeVM = attributeVM;
     _isDebug     = attributeVM.IsDebug;
     _connect     = attributeVM.Connect;
     _isReadOnly  = attributeVM.IsReadOnly;
     _table       = attributeVM.Table;
     _pkAttribute = attributeVM.AttributesListVM.PkAttribute;
     _style       = new PgM.PgStyleObjectM(_table, _pkAttribute.Value);
 }
Ejemplo n.º 3
0
        public CosmeticAttributesVM(AbsM.ITableBaseM table, int?obj, bool isReadOnly = false, string wkt = null, bool isDebug = false)
        {
            _table = table as CosM.CosmeticTableBaseM;
            if (_table == null)
            {
                throw new ArgumentNullException(Rekod.Properties.Resources.CosAttributes_TableIsNull);
            }
            else if (_table.PrimaryKeyField == null)
            {
                throw new ArgumentNullException(Rekod.Properties.Resources.CosAttributes_TableWithoutPK);
            }
            if (obj == null)
            {
                throw new ArgumentNullException(Rekod.Properties.Resources.CosAttributes_MvObjectIsNull);
            }

            _isDebug = isDebug;
            _source  = _table.Source as CosVM.CosmeticDataRepositoryVM;

            _tableObject = GetOrCreateTableObject(obj);

            _attributesListVM = new CosmeticAttributesListVM(this);

            if (_table.Type == AbsM.ETableType.MapLayer || _table.Type == AbsM.ETableType.View)
            {
                string curWKT = string.Empty;
                if (string.IsNullOrWhiteSpace(wkt))
                {
                    var layerMV = Source.MapViewer.getLayer(_table.NameMap);
                    if (layerMV != null)
                    {
                        var objMV = layerMV.getObject(_tableObject.Id);
                        if (objMV != null)
                        {
                            curWKT = objMV.getWKT();
                        }
                    }
                }
                else
                {
                    curWKT = wkt;
                }
                _pgGeometryVM = new PgVM.PgAttributes.PgAttributesGeomVM(_attributesListVM, curWKT, (int?)_attributesListVM.PkAttribute.Value);
            }

            _styleVM = GetStyle();
            Title    = String.Format("{0}: [id: {3}]; {1}: \"{4}\"; {2}: \"{5}\"",
                                     Rekod.Properties.Resources.CosAttributes_Object,
                                     Rekod.Properties.Resources.CosAttributes_Table,
                                     Rekod.Properties.Resources.CosAttributes_Type,
                                     _tableObject != null ? _tableObject.Id.ToString() : "null",
                                     _table.Text,
                                     _table.Source.Type);
        }
Ejemplo n.º 4
0
        public static BitmapImage GetPreviewStyleLine(PgM.PgStyleObjectM collection)
        {
            var newPictures = new Bitmap(32, 32);
            var rectMain    = new Rectangle(0, 0, 32, 32);

            var graphics = Graphics.FromImage(newPictures);
            var brFC     = PgM.PgStyleObjectM.convColor((uint)collection.BrushFgColor);
            var brBC     = PgM.PgStyleObjectM.convColor((uint)collection.BrushBgColor);

            // Фон картинки
            graphics.FillRectangle(SystemBrushes.Window, rectMain);

            // Линия
            ColorPalette pal;
            var          pen = lineRes.ResourceManager.GetObject(String.Format("LINE{0:00}", collection.PenType)) as Image;

            if (pen != null)
            {
                pal            = pen.Palette;
                pal.Entries[1] = Color.FromArgb(0, 0, 0, 0);
                pal.Entries[0] = PgM.PgStyleObjectM.convColor((uint)collection.PenColor);
                pen.Palette    = pal;

                for (int i = 0; i < collection.PenWidth; i++)
                {
                    graphics.DrawImage(pen, new Rectangle(4, i + 2 - collection.PenWidth / 2 + 16, 32, 1), 5, 6, 32, 1, GraphicsUnit.Pixel);
                }
                graphics.Transform.Reset();
            }
            // Конвертирует из System.Drawing в BitmapImage
            using (var stream = new MemoryStream())
            {
                newPictures.Save(stream, ImageFormat.Bmp);

                stream.Position = 0;
                var result = new BitmapImage();
                result.BeginInit();
                result.CacheOption  = BitmapCacheOption.OnLoad;
                result.StreamSource = stream;
                result.EndInit();
                result.Freeze();
                return(result);
            }
        }
Ejemplo n.º 5
0
        public static BitmapImage GetPreviewStylePoint(PgM.PgStyleObjectM collection)
        {
            var newPictures = new Bitmap(32, 32);
            var rectMain    = new Rectangle(0, 0, 32, 32);

            var graphics = Graphics.FromImage(newPictures);
            var brFC     = PgM.PgStyleObjectM.convColor((uint)collection.BrushFgColor);
            var brBC     = PgM.PgStyleObjectM.convColor((uint)collection.BrushBgColor);

            // Фон картинки
            graphics.FillRectangle(SystemBrushes.Window, rectMain);

            // Символ точечного объекта
            var font = new Font(collection.FontName, collection.FontSize);
            var sf   = new StringFormat(StringFormatFlags.NoClip)
            {
                LineAlignment = StringAlignment.Center
            };
            var fontColor = new SolidBrush(PgM.PgStyleObjectM.convColor((uint)collection.FontColor));

            graphics.DrawString(((char)collection.Symbol).ToString(), font, fontColor, rectMain, sf);

            // Конвертирует из System.Drawing в BitmapImage
            using (var stream = new MemoryStream())
            {
                newPictures.Save(stream, ImageFormat.Bmp);

                stream.Position = 0;
                var result = new BitmapImage();
                result.BeginInit();
                result.CacheOption  = BitmapCacheOption.OnLoad;
                result.StreamSource = stream;
                result.EndInit();
                result.Freeze();
                return(result);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Функция считывания с БД
        /// </summary>
        /// <param name="listAttributeRef"> Список </param>
        /// <param name="listSqlRefTable"></param>
        private void GetCollectionOfVariandsForBD(List <PgAtM.PgAttributeM> listAttributeRef, List <string> listSqlRefTable)
        {
            List <IParams> ParamsArray = new List <IParams>();

            for (int i = 0; i < listAttributeRef.Count; i++)
            {
                var item = listAttributeRef[i];
                ParamsArray.Add(new Params(":value" + item.Field.Id, PgAtM.PgAttributeM.GetValue(item), (item.Field as PgM.PgFieldM).DbType));
            }
            if (listSqlRefTable.Count > 0)
            {
                using (var sqlCmd = new SqlWork(_connect, _isDebug))
                {
                    sqlCmd.sql = string.Join(";\n", listSqlRefTable.ToArray());
                    sqlCmd.ExecuteMultipleReader(ParamsArray);
                    int i = 0;
                    do
                    {
                        var item = listAttributeRef[i++];
                        item.Variants.Clear();
                        while (sqlCmd.CanRead())
                        {
                            var id        = sqlCmd.GetValue <object>((item.Field as PgM.PgFieldM).RefTable.PrimaryKeyField.Name);
                            var fieldName = sqlCmd.GetValue <string>((item.Field as PgM.PgFieldM).RefFieldName.Name);
                            var idValue   = sqlCmd.GetValue <object>((item.Field as PgM.PgFieldM).RefField.Name);

                            PgM.PgStyleObjectM style = null;
                            if ((item.Field as PgM.PgFieldM).RefTable.IsMapStyle && LoadStyle)
                            {
                                style = new PgM.PgStyleObjectM((item.Field as PgM.PgFieldM).RefTable, id);

                                style.SetFont(
                                    name: sqlCmd.GetString("!fontname"),
                                    color: sqlCmd.GetValue <int>("!fontcolor"),
                                    frameColor: sqlCmd.GetValue <int>("!fontframecolor"),
                                    size: sqlCmd.GetInt32("!fontsize"));
                                style.SetSymbol(
                                    shape: sqlCmd.GetValue <int>("!symbol"));
                                style.SetPen(
                                    color: sqlCmd.GetValue <int>("!pencolor"),
                                    type: sqlCmd.GetValue <int>("!pentype"),
                                    width: sqlCmd.GetValue <int>("!penwidth"));
                                style.SetBrush(
                                    bgColor: sqlCmd.GetValue <int>("!brushbgcolor"),
                                    fgColor: sqlCmd.GetValue <int>("!brushfgcolor"),
                                    style: sqlCmd.GetValue <int>("!brushstyle"),
                                    hatch: sqlCmd.GetValue <int>("!brushhatch"));
                            }

                            if ((item.Field as PgM.PgFieldM).RefType == AbsM.ERefType.Reference)
                            {
                                item.Variants.Add(new PgAtM.PgAttributeReferenceM(item, fieldName, style, idValue));
                            }
                            else if ((item.Field as PgM.PgFieldM).RefType == AbsM.ERefType.Interval)
                            {
                                var intervalMin = ExtraFunctions.Converts.To <double>(idValue);
                                var intervalMax = sqlCmd.GetValue <double>((item.Field as PgM.PgFieldM).RefFieldEnd.Name);
                                item.Variants.Add(new PgAtM.PgAttributeIntervalM(item, fieldName, style, id, intervalMin, intervalMax));
                            }
                            else if ((item.Field as PgM.PgFieldM).RefType == AbsM.ERefType.Data)
                            {
                                item.Variants.Add(new PgAtM.PgAttributeReferenceM(item, fieldName, style, idValue));
                            }
                        }
                    } while (sqlCmd.CanNextResult());
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Получить сохраненный стиль объекта или экземпляр стиля по умолчанию
        /// </summary>
        /// <returns></returns>
        private PgM.PgStyleObjectM GetStyle()
        {
            PgM.PgStyleObjectM     result = null;
            CosM.CosmeticStyleType type   = CosM.CosmeticStyleType.All;
            if (_pgGeometryVM != null && !String.IsNullOrEmpty(_pgGeometryVM.GeometryTypeName))
            {
                switch (_pgGeometryVM.GeometryTypeName.ToUpper())
                {
                case "POINT":
                case "MULTIPOINT":
                    type = CosM.CosmeticStyleType.Point;
                    break;

                case "LINE":
                case "MULTILINE":
                case "LINESTRING":
                case "MULTILINESTRING":
                    type = CosM.CosmeticStyleType.Line;
                    break;

                case "POLYGON":
                case "MULTIPOLYGON":
                    type = CosM.CosmeticStyleType.Polygon;
                    break;
                }
                var layer    = _source.MapViewer.getLayer(Table.Name);
                var layerObj = layer.getObject(TableObject.Id);
                if (layerObj != null)
                {
                    int objStyleId = layerObj.style;
                    if (Table.DefaultDotStyle == objStyleId || Table.DefaultLineStyle == objStyleId || Table.DefaultPolygonStyle == objStyleId)
                    {
                        result = Table.DefaultStyle.GetStyleInstance(type);
                    }
                    else
                    {
                        HasOwnStyle = true;
                        mvLayerStyle mvStyle = layer.getStyle(objStyleId);
                        result = new PgM.PgStyleObjectM(type)
                        {
                            FontName = "Map Symbols"
                        };
                        if (mvStyle.Brush != null)
                        {
                            result.BrushBgColor = (int)mvStyle.Brush.bgcolor;
                            result.BrushFgColor = (int)mvStyle.Brush.fgcolor;
                            result.BrushHatch   = mvStyle.Brush.hatch;
                            result.BrushStyle   = mvStyle.Brush.style;
                            if (mvStyle.Brush.hatch == 0 && mvStyle.Brush.style == 0)
                            {
                                var tt = (mvStyle.Brush.bgcolor >> 24);
                                result.Opacity = (mvStyle.Brush.bgcolor % 256) / 256d;
                            }
                            if (mvStyle.Brush.bgcolor == 4294967295)
                            {
                                result.HasBackground = false;
                            }
                            else
                            {
                                result.HasBackground = true;
                            }
                        }
                        if (mvStyle.Font != null)
                        {
                            result.FontColor      = (int)mvStyle.Font.Color;
                            result.FontFrameColor = (int)mvStyle.Font.framecolor;
                            result.FontName       = mvStyle.Font.fontname;
                            result.FontSize       = mvStyle.Font.size;
                        }
                        if (mvStyle.Pen != null)
                        {
                            result.PenColor = (int)mvStyle.Pen.Color;
                            result.PenType  = (int)mvStyle.Pen.ctype;
                            result.PenWidth = (int)mvStyle.Pen.width;
                        }
                        if (mvStyle.Symbol != null)
                        {
                            result.Symbol = (int)mvStyle.Symbol.shape;
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 8
0
        public static BitmapImage GetPreviewStylePoligon(PgM.PgStyleObjectM collection)
        {
            var newPictures = new Bitmap(32, 32);

            var          graphics = Graphics.FromImage(newPictures);
            var          brFC     = PgM.PgStyleObjectM.convColor((uint)collection.BrushFgColor);
            var          brBC     = PgM.PgStyleObjectM.convColor((uint)collection.BrushBgColor);
            ColorPalette pal;

            // Заливка полигона
            var brush = ImageBrushRes.ResourceManager.GetObject(String.Format("poly_{0}_{1}", collection.BrushStyle, collection.BrushHatch)) as Image;

            if (brush != null)
            {
                pal = brush.Palette;
                if (pal.Entries.Length == 2)
                {
                    pal.Entries[0] = brFC;
                    pal.Entries[1] = brBC;
                }
                else if (pal.Entries.Length == 1)
                {
                    pal.Entries[0] = brBC;
                }
                brush.Palette = pal;
                graphics.DrawImage(brush, 0, 0, brush.Size.Width, brush.Size.Height);//20, (float)Bounds.Height - 4);
            }

            // Границы полигона
            var pen = lineRes.ResourceManager.GetObject(String.Format("LINE{0:00}", collection.PenType)) as Image;

            if (pen != null)
            {
                pal            = pen.Palette;
                pal.Entries[1] = Color.FromArgb(0, 0, 0, 0);
                pal.Entries[0] = Color.Brown;
                pen.Palette    = pal;

                for (int i = 0; i < 5; i++)
                {
                    graphics.DrawImage(pen, new Rectangle(0, i, 32, 1), 5, 6, 32, 1,
                                       GraphicsUnit.Pixel);
                    graphics.DrawImage(pen, new Rectangle(0, 32 - i, 32, 1), 5, 6, 32, 1,
                                       GraphicsUnit.Pixel);
                }

                var matr = new Matrix();
                matr.RotateAt(90, new PointF(16, 16));
                graphics.Transform = matr;
                for (int i = 0; i < 5; i++)
                {
                    graphics.DrawImage(pen, new Rectangle(0, i, 32, 1), 5, 6, 32, 1, GraphicsUnit.Pixel);
                    graphics.DrawImage(pen, new Rectangle(0, 32 - i, 32, 1), 5, 6, 32, 1,
                                       GraphicsUnit.Pixel);
                }
                graphics.Transform.Reset();
            }
            // Конвертирует из System.Drawing в BitmapImage
            using (var stream = new MemoryStream())
            {
                newPictures.Save(stream, ImageFormat.Bmp);

                stream.Position = 0;
                var result = new BitmapImage();
                result.BeginInit();
                result.CacheOption  = BitmapCacheOption.OnLoad;
                result.StreamSource = stream;
                result.EndInit();
                result.Freeze();
                return(result);
            }
        }