예제 #1
0
        public bool CopyModelAndImage(MyProgressBar bar, IFeatureDataSet srcFds, IFeatureDataSet tarFds)
        {
            bool flag = true;
            int  num  = 1;

            try
            {
                tarFds.DataSource.StartEditing();
                IResourceManager resourceManager  = srcFds as IResourceManager;
                IResourceManager resourceManager2 = tarFds as IResourceManager;
                EnumResName      modelNames       = resourceManager.GetModelNames();
                int modelCount = resourceManager.GetModelCount();
                while (modelNames.MoveNext())
                {
                    if (num % 100 == 0 || num == modelCount)
                    {
                        lock (bar)
                        {
                            if (bar.CallbackCancel)
                            {
                                bar.labelTooltip.Text = StringParser.Parse("${res:View_Cancling}");
                                bool result = false;
                                return(result);
                            }
                        }
                    }
                    string current = modelNames.Current;
                    Gvitech.CityMaker.Resource.IModel model           = resourceManager.GetModel(current);
                    Gvitech.CityMaker.Resource.IModel simplifiedModel = resourceManager.GetSimplifiedModel(current);
                    if (!resourceManager2.ModelExist(current))
                    {
                        resourceManager2.AddModel(current, model, simplifiedModel);
                        LoggingService.Debug(string.Format("Copy model:{0}", current));
                    }
                    num++;
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(modelNames);
                EnumResName imageNames = resourceManager.GetImageNames();
                num = 1;
                resourceManager.GetImageCount();
                while (imageNames.MoveNext())
                {
                    if (num % 100 == 0 || num == modelCount)
                    {
                        lock (bar)
                        {
                            if (bar.CallbackCancel)
                            {
                                bar.labelTooltip.Text = StringParser.Parse("${res:View_Cancling}");
                                bool result = false;
                                return(result);
                            }
                        }
                    }
                    string current2 = imageNames.Current;
                    IImage image    = resourceManager.GetImage(current2);
                    if (image != null && !resourceManager2.ImageExist(current2))
                    {
                        resourceManager2.AddImage(current2, image);
                        LoggingService.Debug(string.Format("Copy model:{0}", current2));
                    }
                    num++;
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(imageNames);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                flag = false;
            }
            catch (System.Exception ex2)
            {
                XtraMessageBox.Show(ex2.Message);
                flag = false;
            }
            finally
            {
                tarFds.DataSource.StopEditing(flag);
            }
            return(flag);
        }
예제 #2
0
        private IEnvelope ImportOsg(IFeatureClass fc, string filePath)
        {
            try
            {
                IEnvelope env = null;

                if (fc == null || !File.Exists(filePath))
                {
                    return(env);
                }

                string           modelName       = Path.GetFileNameWithoutExtension(filePath);
                IResourceManager resourceManager = fc.FeatureDataSet as IResourceManager;
                if (resourceManager == null)
                {
                    return(env);
                }
                if (!resourceManager.CheckResourceName(modelName))
                {
                    return(env);
                }
                IResourceFactory resourceFactory = new ResourceFactory();

                System.Collections.Generic.Dictionary <string, IEnvelope> modelInfos = this.GetModelInfos(resourceManager, modelName);
                fc.FeatureDataSet.DataSource.StartEditing();
                if (modelInfos.Keys.Contains(modelName))
                {
                    if (!sameNameDlg.IsApplicatonAll)//非应用于全部
                    {
                        string tipMessage = string.Format("{0}模型已经存在!", modelName);
                        sameNameDlg.TipMessage = tipMessage;
                        sameNameDlg.ShowDialog();
                    }
                    if (sameNameDlg.IsOverWriter)//如果覆盖就先删除
                    {
                        resourceManager.DeleteModel(modelName);
                        modelInfos.Remove(modelName);
                    }
                    else
                    {
                        env = modelInfos[modelName];
                    }
                }
                if (!modelInfos.Keys.Contains(modelName))
                {
                    Gvitech.CityMaker.Resource.IModel simplifiedModel = null;
                    Gvitech.CityMaker.Resource.IModel model           = null;
                    IMatrix      matrix = null;
                    IPropertySet propertySet;
                    resourceFactory.CreateModelAndImageFromFileEx(filePath, out propertySet, out simplifiedModel, out model, out matrix);
                    if (model == null || model.GroupCount == 0)
                    {
                        return(env);
                    }
                    if (!resourceManager.AddModel(modelName, model, simplifiedModel))
                    {
                        return(env);                                                             //向资源中添加
                    }
                    modelInfos[modelName] = model.Envelope;
                    env = modelInfos[modelName];

                    if (propertySet != null && propertySet.Count > 0)
                    {
                        //获得资源的图片
                        System.Collections.Generic.List <string> imageNames = GetImageNames(resourceManager);
                        string[] allKeys = propertySet.GetAllKeys();
                        string[] array   = allKeys;
                        for (int i = 0; i < array.Length; i++)
                        {
                            string text2 = array[i];
                            if (imageNames.Contains(text2))
                            {
                                if (!sameNameDlg.IsApplicatonAll)//非应用于全部
                                {
                                    string tipMessage2 = string.Format("{0}贴图已存在!", text2);
                                    sameNameDlg.TipMessage = tipMessage2;
                                    sameNameDlg.ShowDialog();
                                }
                                if (sameNameDlg.IsOverWriter)//是否覆盖
                                {
                                    resourceManager.DeleteImage(text2);
                                    imageNames.Remove(text2);
                                }
                            }

                            if (!imageNames.Contains(text2))
                            {
                                if (!resourceManager.CheckResourceName(text2))
                                {
                                }
                                else
                                {
                                    imageNames.Add(text2);
                                    Gvitech.CityMaker.Resource.IImage image = propertySet.GetProperty(text2) as Gvitech.CityMaker.Resource.IImage;
                                    resourceManager.AddImage(text2, image);
                                }
                            }
                        }
                    }
                }
                fc.FeatureDataSet.DataSource.StopEditing(true);
                return(env);
            }
            catch (Exception ex)
            {
                fc.FeatureDataSet.DataSource.StopEditing(false);
                return(null);
            }
        }