Esempio n. 1
0
        /// <summary>
        /// Создает объект в списке
        /// Если объект существует на карте, то его значение обновляется, иначе объект создается
        /// </summary>
        /// <param name="label">Значение подписи</param>
        /// <param name="wkt">Геометрия</param>
        /// <param name="mapObj">Объект на карте</param>
        /// <returns>Созданный объект</returns>
        public CosmeticObjectM CreateObject(string label, string wkt, mvVectorObject mapObj = null)
        {
            var tableObj = new CosmeticObjectM(NextObjectId, wkt);

            tableObj.SetAttribute("label", label);
            Objects.Add(tableObj);

            var layerMV = (Source as SourceCosmetic.ViewModel.CosmeticDataRepositoryVM).MapViewer.getLayer(NameMap);

            if (layerMV != null && tableObj != null)
            {
                if (mapObj == null)
                {
                    mapObj = layerMV.getObject(tableObj.Id);
                    if (mapObj == null)
                    {
                        mapObj = layerMV.CreateObject();
                    }
                }

                if (mapObj != null)
                {
                    mapObj.setWKT(wkt);
                    mapObj.SetAttribute("label", label);
                    mapObj.SetAttribute(PkFieldName, tableObj.Id.ToString());
                }
            }

            return(tableObj);
        }
        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);
        }
        /// <summary>
        /// Создать объект, если его не существует
        /// </summary>
        private CosM.CosmeticObjectM GetOrCreateTableObject(int?obj)
        {
            CosM.CosmeticObjectM tableObject = null;

            var layerMV = Source.MapViewer.getLayer(_table.NameMap);

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

            int id = obj.Value;

            string wkt   = string.Empty;
            var    objMV = layerMV.getObject(id);

            if (objMV != null)
            {
                wkt = objMV.getWKT();
            }

            tableObject = _table.GetObject(id);
            if (tableObject == null)
            {
                tableObject = new CosM.CosmeticObjectM(id, wkt);
            }

            if (objMV != null)
            {
                foreach (var field in _table.Fields)
                {
                    if (field.Name != _table.GeomFieldName &&
                        field.Name != _table.PkFieldName)
                    {
                        tableObject.SetAttribute(field.Name, (string)objMV.fieldValue(field.Name));
                    }
                }
            }

            return(tableObject);
        }