Ejemplo n.º 1
0
        ///<summary>
        ///获取符号库中符号
        ///</summary>
        ///<param name="sServerStylePath">符号库全路径名称</param>
        ///<param name="sGalleryClassName">GalleryClass名称</param>
        ///<param name="symbolName">符号名称</param>
        ///<returns>符号</returns>
        private ISymbol GetSymbol(string sServerStylePath, string sGalleryClassName, string symbolName)
        {
            try
            {
                //ServerStyleGallery对象
                IStyleGallery        pStyleGaller         = new ServerStyleGalleryClass();
                IStyleGalleryStorage pStyleGalleryStorage = pStyleGaller as IStyleGalleryStorage;

                IEnumStyleGalleryItem pEnumSyleGalleryItem = null;
                IStyleGalleryItem     pStyleGallerItem     = null;
                IStyleGalleryClass    pStyleGalleryClass   = null;
                //使用IStyleGalleryStorage接口的AddFile方法加载ServerStyle文件
                pStyleGalleryStorage.AddFile(sServerStylePath);
                //遍历ServerGallery中的Class
                for (int i = 0; i < pStyleGaller.ClassCount; i++)
                {
                    pStyleGalleryClass = pStyleGaller.get_Class(i);
                    if (pStyleGalleryClass.Name != sGalleryClassName)
                    {
                        continue;
                    }
                    //获取EnumStyleGalleryItem对象
                    pEnumSyleGalleryItem = pStyleGaller.get_Items(sGalleryClassName, sServerStylePath, "");
                    pEnumSyleGalleryItem.Reset();
                    //遍历pEnumSyleGalleryItem
                    pStyleGallerItem = pEnumSyleGalleryItem.Next();
                    while (pStyleGallerItem != null)
                    {
                        if (pStyleGallerItem.Name == symbolName)
                        {
                            //获取符号
                            ISymbol pSymbol = pStyleGallerItem.Item as ISymbol;
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumSyleGalleryItem);
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGalleryClass);
                            return(pSymbol);
                        }
                        pStyleGallerItem = pEnumSyleGalleryItem.Next();
                    }
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumSyleGalleryItem);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGalleryClass);
                return(null);
            }
            catch (Exception Err)
            {
                MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取指定种类,指定符号id的符号
        /// </summary>
        /// <param name="sGallery">符号种类(e.g.填充颜色)</param>
        /// <param name="id">符号id</param>
        /// <returns>符号</returns>
        public static ISymbol GetStyleSymbol(string sGallery, int id)
        {
            try
            {
                IStyleGallery        pStyleGallery        = new ServerStyleGalleryClass();
                IStyleGalleryStorage pStyleGalleryStorage = pStyleGallery as IStyleGalleryStorage;

                for (int i = pStyleGalleryStorage.FileCount - 1; i >= 0; i--)
                {
                    pStyleGalleryStorage.RemoveFile(pStyleGalleryStorage.get_File(i));
                }

                pStyleGalleryStorage.AddFile(_STYLEFILE);
                IEnumStyleGalleryItem pEnumStyleItem = pStyleGallery.get_Items(sGallery, _STYLEFILE, "");
                pEnumStyleItem.Reset();
                IStyleGalleryItem  mStyleItem  = pEnumStyleItem.Next();
                IStyleGalleryClass mStyleClass = null;
                for (int i = 0; i < pStyleGallery.ClassCount; i++)
                {
                    mStyleClass = pStyleGallery.get_Class(i);
                    string str = mStyleClass.Name;
                    if (str == sGallery)
                    {
                        break;
                    }
                }

                ISymbol result = null;
                while (mStyleItem != null)
                {
                    if (mStyleItem.ID == id)
                    {
                        result = mStyleItem.Item as ISymbol;
                        break;
                    }
                    mStyleItem = pEnumStyleItem.Next();
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumStyleItem);
                return(result);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 读取ServerStyle中的文件并显示
        /// </summary>
        /// <param name="StyleGalleryClass">符号文件的种类</param>
        /// <param name="CategoryClass">符号的种类</param>
        /// <param name="cbxCategory">符号文件的种类的容器</param>
        /// <param name="lvSymbol">符号位图的容器</param>
        public static void ReadServerStyle(string StyleGalleryClass, string CategoryClass, ComboBox cbxCategory, ListView lvSymbol)
        {
            lvSymbol.Items.Clear();
            lvSymbol.LargeImageList.Images.Clear();
            IStyleGallery        pStyleGallery        = new ServerStyleGalleryClass();
            IStyleGalleryStorage pStyleGalleryStorage = pStyleGallery as IStyleGalleryStorage;

            // 增加符号文件
            //pStyleGalleryStorage.TargetFile = _STYLEFILE;
            for (int i = pStyleGalleryStorage.FileCount - 1; i >= 0; i--)
            {
                pStyleGalleryStorage.RemoveFile(pStyleGalleryStorage.get_File(i));
            }
            pStyleGalleryStorage.AddFile(_STYLEFILE);
            // 根据当前符号的类别和文件得到符号的枚举循环子,符号类别包括Fill Symbol,Line Symbol等
            IEnumStyleGalleryItem pEnumStyleItem = pStyleGallery.get_Items(StyleGalleryClass, _STYLEFILE, "");

            // 得到符号文件类别的各个条目,增加到一个Combox中
            if (cbxCategory != null)
            {
                cbxCategory.Items.Clear();
                cbxCategory.Items.Add(_ALLSYMBOLS);
                IEnumBSTR pEnumBSTR = pStyleGallery.get_Categories(StyleGalleryClass);
                pEnumBSTR.Reset();
                string Category = "";
                Category = pEnumBSTR.Next();
                while (Category != null)
                {
                    cbxCategory.Items.Add(Category);
                    Category = pEnumBSTR.Next();
                }
            }

            pEnumStyleItem.Reset();
            IStyleGalleryItem  mStyleItem  = pEnumStyleItem.Next();
            IStyleGalleryClass mStyleClass = null;

            for (int i = 0; i < pStyleGallery.ClassCount; i++)
            {
                mStyleClass = pStyleGallery.get_Class(i);
                string str = mStyleClass.Name;
                if (str == StyleGalleryClass)
                {
                    break;
                }
            }

            // 得到各个符号并转化为图片
            int       ImageIndex = 0;
            ImageList Largeimage = lvSymbol.LargeImageList;

            if (CategoryClass == "" || CategoryClass == _ALLSYMBOLS)
            {
                while (mStyleItem != null)
                {
                    // 调用另一个类的方法将符号转化为图片
                    Bitmap bmpB = StyleGalleryItemToBmp(32, 32, mStyleClass, mStyleItem);
                    Largeimage.Images.Add(bmpB);
                    ListViewItem lvItem = new ListViewItem(new string[] { mStyleItem.Name, mStyleItem.ID.ToString(), mStyleItem.Category }, ImageIndex);
                    lvSymbol.Items.Add(lvItem);
                    ImageIndex++;
                    mStyleItem = pEnumStyleItem.Next();
                }
            }
            else
            {
                while (mStyleItem != null)
                {
                    if (CategoryClass == mStyleItem.Category)
                    {
                        // 调用另一个类的方法将符号转化为图片
                        Bitmap bmpB = StyleGalleryItemToBmp(32, 32, mStyleClass, mStyleItem);
                        Largeimage.Images.Add(bmpB);
                        ListViewItem lvItem = new ListViewItem(new string[] { mStyleItem.Name, mStyleItem.ID.ToString(), mStyleItem.Category }, ImageIndex);
                        lvSymbol.Items.Add(lvItem);
                        ImageIndex++;
                    }
                    mStyleItem = pEnumStyleItem.Next();
                }
            }
            // 必须采用此方式进行释放,第二次才能正常读取
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumStyleItem);
        }
Ejemplo n.º 4
0
        ///<summary>
        ///��ȡ���ſ��з���
        ///</summary>
        ///<param name="sServerStylePath">���ſ�ȫ·������</param>
        ///<param name="sGalleryClassName">GalleryClass����</param>
        ///<param name="symbolName">��������</param>
        ///<returns>����</returns>
        private ISymbol GetSymbol(string sServerStylePath, string sGalleryClassName, string symbolName)
        {
            try
            {
                //ServerStyleGallery����
                IStyleGallery pStyleGaller = new ServerStyleGalleryClass();
                IStyleGalleryStorage pStyleGalleryStorage = pStyleGaller as IStyleGalleryStorage;

                IEnumStyleGalleryItem pEnumSyleGalleryItem = null;
                IStyleGalleryItem pStyleGallerItem = null;
                IStyleGalleryClass pStyleGalleryClass = null;
                //ʹ��IStyleGalleryStorage�ӿڵ�AddFile��������ServerStyle�ļ�
                pStyleGalleryStorage.AddFile(sServerStylePath);
                //����ServerGallery�е�Class
                for (int i = 0; i < pStyleGaller.ClassCount; i++)
                {
                    pStyleGalleryClass = pStyleGaller.get_Class(i);
                    if (pStyleGalleryClass.Name != sGalleryClassName)
                        continue;
                    //��ȡEnumStyleGalleryItem����
                    pEnumSyleGalleryItem = pStyleGaller.get_Items(sGalleryClassName, sServerStylePath, "");
                    pEnumSyleGalleryItem.Reset();
                    //����pEnumSyleGalleryItem
                    pStyleGallerItem = pEnumSyleGalleryItem.Next();
                    while (pStyleGallerItem != null)
                    {
                        if (pStyleGallerItem.Name == symbolName)
                        {
                            //��ȡ����
                            ISymbol pSymbol = pStyleGallerItem.Item as ISymbol;
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumSyleGalleryItem);
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGalleryClass);
                            return pSymbol;
                        }
                        pStyleGallerItem = pEnumSyleGalleryItem.Next();
                    }
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumSyleGalleryItem);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGalleryClass);
                return null;
            }
            catch (Exception Err)
            {
                MessageBox.Show(Err.Message, "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return null;
            }
        }