예제 #1
0
        public int GetFeatureCount(IFeatureDataSet fds, QueryFilter filter)
        {
            int num = 0;

            try
            {
                string[] namesByType = fds.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (namesByType != null)
                {
                    string[] array = namesByType;
                    for (int i = 0; i < array.Length; i++)
                    {
                        string        name         = array[i];
                        IFeatureClass featureClass = fds.OpenFeatureClass(name);
                        if (featureClass != null)
                        {
                            num += featureClass.GetCount(filter);
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                        }
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
            }
            catch (System.Exception e)
            {
                LoggingService.Error(e.Message + "\r\n" + e.StackTrace);
            }
            return(num);
        }
예제 #2
0
        /// <summary>
        /// 通过modelPoint查找model,修改model顶点,塞回数据源
        /// </summary>
        /// <param name="fdbPath"></param>
        void editModleNodeCoord(string fdbPath)
        {
            IConnectionInfo ci = new ConnectionInfo();

            ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
            ci.Database       = fdbPath;

            //获取数据源
            IDataSource ds = new DataSourceFactory().OpenDataSource(ci);

            string[]         dataSetNames = ds.GetFeatureDatasetNames();
            IFeatureDataSet  fds          = ds.OpenFeatureDataset("fdsName");
            IResourceManager resourceM    = (IResourceManager)fds;

            //获取所有featureClass
            string[] fcNames = fds.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
            for (int fci = 0; fci < fcNames.Length; fci++)
            {
                IFeatureClass        fc         = fds.OpenFeatureClass(fcNames[fci]);
                IFieldInfoCollection fieldInfos = fc.GetFields();
                for (int fieldi = 0; fieldi < fieldInfos.Count; fieldi++)
                {
                    IFieldInfo finfo = fieldInfos.Get(fieldi);
                    if (finfo.FieldType == gviFieldType.gviFieldGeometry)
                    {
                        //获取fc的几何属性及其索引,索引用于更新模型
                        aaa(fc, fieldi, resourceM);
                        break;
                    }
                }
            }
        }
예제 #3
0
        private void LoadLocalData()
        {
            try
            {
                ConnectionInfo ci = new ConnectionInfo
                {
                    ConnectionType = i3dConnectionType.i3dConnectionFireBird2x
                };
                string rootPath   = Path.GetFullPath(@"..//..//..");
                string tmpFDBPath = Path.Combine(rootPath, "data\\3dm\\1.3DM");

                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                datasetCRS = dataset.SpatialReference;
                string[] fcnames = (string[])dataset.GetNamesByType(i3dDataSetType.i3dDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
        }
예제 #4
0
        public void CompareFeatureDataSet(IFeatureDataSet target, IFeatureDataSet origin, out System.Collections.Hashtable fcmap)
        {
            fcmap = new System.Collections.Hashtable();
            IFeatureClass featureClass  = null;
            IFeatureClass featureClass2 = null;

            try
            {
                string[] namesByType  = target.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                string[] namesByType2 = origin.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                string[] array        = namesByType2;
                for (int i = 0; i < array.Length; i++)
                {
                    string text = array[i];
                    featureClass = origin.OpenFeatureClass(text);
                    if (namesByType != null)
                    {
                        string[] array2 = namesByType;
                        for (int j = 0; j < array2.Length; j++)
                        {
                            string text2 = array2[j];
                            if (text.Equals(text2))
                            {
                                featureClass2 = target.OpenFeatureClass(text2);
                                if (this.CompareFeatureClass(featureClass.GetFields(), featureClass2.GetFields()))
                                {
                                    fcmap.Add(text, text2);
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException)
            {
            }
            catch (System.Exception)
            {
            }
            finally
            {
                if (featureClass != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                    featureClass = null;
                }
                if (featureClass2 != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass2);
                    featureClass2 = null;
                }
            }
        }
예제 #5
0
        private void FeatureDataSetMapToFeatureClassMap()
        {
            try
            {
                if (_ci == null)
                {
                    return;
                }
                dsFactory = new DataSourceFactory();
                IDataSource ds = dsFactory.OpenDataSource(_ci);

                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames == null || setnames.Length == 0)
                {
                    return;
                }

                foreach (string name in setnames)
                {
                    IFeatureDataSet dataSet = ds.OpenFeatureDataset(name);
                    string[]        fcnames = (string[])dataSet.GetNamesByType(i3dDataSetType.i3dDataSetFeatureClassTable);
                    if (fcnames == null || fcnames.Length == 0)
                    {
                        continue;
                    }
                    foreach (string fcname in fcnames)
                    {
                        IFeatureClass fc = dataSet.OpenFeatureClass(fcname);
                        if (fc != null)
                        {
                            List <string>        geoNames   = new List <string>();
                            IFieldInfoCollection fieldinfos = fc.GetFields();
                            if (fieldinfos != null && fieldinfos.Count > 0)
                            {
                                for (int i = 0; i < fieldinfos.Count; i++)
                                {
                                    IFieldInfo field = fieldinfos.Get(i);
                                    if (field != null && field.GeometryDef != null)
                                    {
                                        geoNames.Add(field.Name);
                                    }
                                }
                                _featureClassMapping.Add(fc, geoNames);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.Logger.Error(ex, "执行FeatureDataSetMapToFeatureClassMap错误");
            }
        }
예제 #6
0
파일: MainForm.cs 프로젝트: batuZ/Samples
        private void deleteDataSetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IDataSource     ds   = null;
            IFeatureDataSet dset = null;

            try
            {
                if (MessageBox.Show("该操作无法恢复,请确定是否删除数据集?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    myTreeNode      node = (myTreeNode)selectNode.Parent;
                    IConnectionInfo ci   = node.con;
                    ds   = dsFactory.OpenDataSource(ci);
                    dset = ds.OpenFeatureDataset(selectNode.Text);

                    Array tem = dset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                    if (tem != null)
                    {
                        foreach (String strFC in tem)
                        {
                            IFeatureClass fc = dset.OpenFeatureClass(strFC);
                            dset.DeleteByName(strFC);
                            //Marshal.ReleaseComObject(fc);
                            fc = null;
                        }
                    }
                    ds.DeleteFeatureDataset(selectNode.Text);

                    // 从普通表里删除dataset对应的记录
                    DeleteLogicTree(ds, selectNode.Text);

                    // 从树上删节点
                    node.Nodes.Remove(selectNode);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
            }
        }
예제 #7
0
 public int TryCeateObjectClass(IFeatureDataSet dataset, string Name, IFieldInfoCollection fields, string[] indexField, out IObjectClass oc)
 {
     oc = null;
     if (((dataset == null) || string.IsNullOrEmpty(Name)) || (fields == null))
     {
         return(-1);
     }
     try
     {
         string[] namesByType = dataset.GetNamesByType(gviDataSetType.gviDataSetObjectClassTable);
         if ((namesByType != null) && (Array.IndexOf <string>(namesByType, Name) != -1))
         {
             oc = dataset.OpenObjectClass(Name);
             return(0);
         }
         oc = dataset.CreateObjectClass(Name, fields);
         if (dataset == null)
         {
             return(-1);
         }
         IDbIndexInfo index = null;
         if (indexField != null)
         {
             foreach (string str in indexField)
             {
                 try
                 {
                     index = new DbIndexInfoClass
                     {
                         Name = string.Format("Index_{0}_{1}", oc.Id, str)
                     };
                     index.AppendFieldDefine(str, true);
                     oc.AddDbIndex(index);
                 }
                 catch (Exception exception)
                 {
                 }
             }
         }
         return(1);
     }
     catch (Exception exception2)
     {
         return(-1);
     }
 }
        /// <summary>
        /// 添加 FeatureClass 到树节点
        /// </summary>
        /// <param name="featureDataSet"></param>
        /// <param name="node"></param>
        public void AppendFeatureClassToTreeNode(IFeatureDataSet featureDataSet, TreeNode node)
        {
            string[] fcnames = (string[])featureDataSet.GetNamesByType(i3dDataSetType.i3dDataSetFeatureClassTable);
            if (fcnames == null || fcnames.Length == 0)
            {
                return;
            }

            foreach (string fcname in fcnames)
            {
                TreeNode fcNode = new TreeNode(fcname, 2, 2);
                node.Nodes.Add(fcNode);

                IFeatureClass fc = featureDataSet.OpenFeatureClass(fcname);
                AppendFieldInfoToTreeNode(fc, fcNode);
            }
        }
예제 #9
0
        public static Dictionary <string, IFeatureClass> GetFeatureClass(IConnectionInfo ci)
        {
            try
            {
                Dictionary <string, IFeatureClass> fcs = new Dictionary <string, IFeatureClass>();
                IDataSourceFactory dsFactory           = new DataSourceFactory();
                if (!dsFactory.HasDataSource(ci))
                {
                    return(null);
                }
                IDataSource ds = dsFactory.OpenDataSource(ci);
                if (ds == null)
                {
                    return(null);
                }
                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return(null);
                }
                for (int j = 0; j < setnames.Length; j++)
                {
                    IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[j]);

                    string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                    if (fcnames.Length == 0)
                    {
                        continue;
                    }
                    foreach (string name in fcnames)
                    {
                        IFeatureClass fc = dataset.OpenFeatureClass(name);
                        if (fc == null)
                        {
                            continue;
                        }
                        fcs[fc.GuidString] = fc;
                    }
                }
                return(fcs);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #10
0
        private void FeatureDataSetMapToFeatureClass()
        {
            try
            {
                if (ci == null)
                {
                    return;
                }
                dsFactory = new DataSourceFactory();
                IDataSource ds = dsFactory.OpenDataSource(ci);

                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames == null || setnames.Length == 0)
                {
                    return;
                }

                featureDataSetMapping = new Dictionary <IFeatureDataSet, List <IFeatureClass> >(setnames.Length);
                foreach (string name in setnames)
                {
                    IFeatureDataSet dataSet = ds.OpenFeatureDataset(name);
                    string[]        fcnames = (string[])dataSet.GetNamesByType(i3dDataSetType.i3dDataSetFeatureClassTable);
                    if (fcnames == null || fcnames.Length == 0)
                    {
                        continue;
                    }
                    featureClasses = new List <IFeatureClass>(fcnames.Length);
                    foreach (string fcname in fcnames)
                    {
                        IFeatureClass fc = dataSet.OpenFeatureClass(fcname);
                        if (fc != null)
                        {
                            featureClasses.Add(fc);
                        }
                    }
                    featureDataSetMapping.Add(dataSet, featureClasses);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #11
0
파일: MainForm.cs 프로젝트: batuZ/Samples
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            // 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\REVIT-ALL2013.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset = ds.OpenFeatureDataset(setnames[0]);
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;

            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        angle.Set(0, -20, 0);
                        point            = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                        point.SpatialCRS = fc.FeatureDataSet.SpatialReference;
                        point.SetCoords(env.Center.X, env.Center.Y, env.Center.Z, 0, 0);
                        this.axRenderControl1.Camera.LookAt2(point, 100, angle);
                    }
                    hasfly = true;
                }
            }

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "Revit.html";
            }
        }
예제 #12
0
        private void SyncTopoInfo()
        {
            try
            {
                IFeatureDataSet fds = this._dsPipe.OpenFeatureDataset("DataSet_BIZ");
                if (fds == null)
                {
                    return;
                }

                List <TopoClass> allTC = GetAllTopoClasses();
                if (allTC == null || allTC.Count == 0)
                {
                    return;
                }

                #region 检查删除管线库中的拓扑信息表,有就不删,没有就删除
                WaitForm.SetCaption("检查管线库中的拓扑信息表...");
                string[] namesByType = fds.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (namesByType == null)
                {
                    return;
                }
                foreach (string str in namesByType)
                {
                    if (str.ToUpper().IndexOf("TOPO_OC_") == 0)
                    {
                        bool flag = true;
                        if ((allTC == null) || (allTC.Count == 0))
                        {
                            flag = true;
                        }
                        else
                        {
                            foreach (TopoClass tc in allTC)
                            {
                                if (tc.TopoTable == str)
                                {
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        if (flag)
                        {
                            fds.DeleteByName(str);
                        }
                    }
                }
                #endregion

                #region 创建拓扑信息表
                WaitForm.SetCaption("创建管线库中的拓扑信息表...");
                foreach (TopoClass tc in allTC)
                {
                    string topoTableName = tc.TopoTable;
                    if (Array.IndexOf <string>(namesByType, topoTableName) == -1)
                    {
                        string[]      arrDBIndex = null;
                        IFeatureClass fc         = fds.CreateFeatureClass(topoTableName, GetTopoInfoFields(out arrDBIndex));
                        if (fc != null)
                        {
                            fc.AliasName = tc.Name + "拓扑信息表";
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("同步管线库中的拓扑信息表失败!", "提示");
            }
        }
예제 #13
0
        /// <summary>
        /// 打开FDB数据
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        List <IFeatureLayer> openFDB(string filePath)
        {
            Hashtable featuerClassList = new Hashtable();

            #region 提取数据
            //连接器
            IConnectionInfo ci = new ConnectionInfo();
            ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;//FDB
            //ci.ConnectionType = gviConnectionType.gviConnectionSQLite3;//SDB
            ci.Password = null;
            ci.Database = filePath;

            //通过连接器打开数据源
            IDataSourceFactory dsFac = new DataSourceFactory();
            IDataSource        ds    = dsFac.OpenDataSource(ci);

            //查找数据源中所有的数据集
            string[] featureDataSetNames = ds.GetFeatureDatasetNames();
            if (featureDataSetNames.Length == 0)
            {
                Console.WriteLine("打开失败!");
                return(null);
            }

            //获取数据集,一般只有一个,多个时要遍历
            IFeatureDataSet dataset = ds.OpenFeatureDataset(featureDataSetNames[0]);

            //查找数据集中的所有要素类
            string[] featureClassNames = dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
            if (featureClassNames.Length == 0)
            {
                Console.WriteLine("没有找到要素类!");
                return(null);
            }
            for (int fci = 0; fci < featureClassNames.Length; fci++)
            {
                IFeatureClass fc = dataset.OpenFeatureClass(featureClassNames[fci]);
                //创建一个容器,放fc的几何属性名称
                List <string> geoNames = new List <string>();
                //查找要素类中所有属性
                IFieldInfoCollection fieldInfos = fc.GetFields();
                for (int fieldi = 0; fieldi < fieldInfos.Count; fieldi++)
                {
                    IFieldInfo fieldinfo = fieldInfos.Get(fieldi);
                    if (fieldinfo == null || fieldinfo.GeometryDef == null)
                    {
                        continue;
                    }
                    geoNames.Add(fieldinfo.Name);
                }
                featuerClassList[fc] = geoNames;
            }
            #endregion

            List <IFeatureLayer> fls = new List <IFeatureLayer>();
            #region 塞入三维对象
            bool hasfly = false;
            foreach (IFeatureClass fc in featuerClassList.Keys)
            {
                List <string> geoNames = (List <string>)featuerClassList[fc];
                foreach (string geoName in geoNames)
                {
                    if (geoName.Equals("Geometry"))
                    {
                        IFeatureLayer fl = axRenderControl.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, Guid.Empty);
                        if (fl != null)
                        {
                            fls.Add(fl);
                        }
                    }

                    //jump once!
                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldInfos = fc.GetFields();
                        IFieldInfo           fieldinfo  = fieldInfos.Get(fieldInfos.IndexOf(geoName));
                        IGeometryDef         gd         = fieldinfo.GeometryDef;
                        IEnvelope            enve       = gd.Envelope;
                        if (enve != null)
                        {
                            axRenderControl.Camera.LookAtEnvelope(enve);
                            hasfly = true;
                        }
                    }
                }
            }
            #endregion

            return(fls);
        }
예제 #14
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            ps.SetProperty("QuadBufferStereo", true);  //设置四缓冲立体启用
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            #region 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }
            #endregion

            // 下拉框控件默认选中第一项
            this.toolStripComboBoxViewportMode.SelectedIndex = 0;

            this.txtEyeSeparation.Text  = this.axRenderControl1.GetRenderParam(gviRenderControlParameters.gviRenderParamStereoEyeSeparation).ToString();
            this.txtFusionDistance.Text = this.axRenderControl1.GetRenderParam(gviRenderControlParameters.gviRenderParamStereoFusionDistance).ToString();
            this.txtScreenDistance.Text = this.axRenderControl1.GetRenderParam(gviRenderControlParameters.gviRenderParamStereoScreenDistance).ToString();

            this.txtFusionDistance.TextChanged += new System.EventHandler(this.txtFusionDistance_TextChanged);
            this.txtEyeSeparation.TextChanged  += new System.EventHandler(this.txtEyeSeparation_TextChanged);
            this.txtScreenDistance.TextChanged += new System.EventHandler(this.txtScreenDistance_TextChanged);

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "StereoDisplay.html";
            }
        }
예제 #15
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            // 加载FDB
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\empty.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);

                TreeNode sourceNode = new TreeNode(ci.Database);
                this.treeViewCatalogTree.Nodes.Add(sourceNode);

                // 获取第1个dataset
                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset = ds.OpenFeatureDataset(setnames[0]);

                TreeNode setNode = new TreeNode(setnames[0]);
                sourceNode.Nodes.Add(setNode);

                // 获取第1个featureclass
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fc = dataset.OpenFeatureClass(fcnames[0]);

                TreeNode fcNode = new TreeNode(fcnames[0]);
                setNode.Nodes.Add(fcNode);

                // 找到空间列字段
                geoNames = new List <string>();
                IFieldInfoCollection fieldinfos = fc.GetFields();
                for (int i = 0; i < fieldinfos.Count; i++)
                {
                    IFieldInfo fieldinfo = fieldinfos.Get(i);
                    if (null == fieldinfo)
                    {
                        continue;
                    }
                    IGeometryDef geometryDef = fieldinfo.GeometryDef;
                    if (null == geometryDef)
                    {
                        continue;
                    }
                    geoNames.Add(fieldinfo.Name);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            layerList = new List <IFeatureLayer>();
            foreach (string geoName in geoNames)
            {
                //****特别注意****
                ISimpleGeometryRender geoRender = new SimpleGeometryRender();
                geoRender.RenderGroupField = "Groupid";
                //****************
                IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                    fc, geoName, null, geoRender, rootId);
                layerList.Add(featureLayer);

                // 设置featureLayer可见
                SetGroupVisiable(dataset, featureLayer);

                IFieldInfoCollection fieldinfos  = fc.GetFields();
                IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                IEnvelope            env         = geometryDef.Envelope;
                if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                    env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                {
                    continue;
                }
                IEulerAngle angle = new EulerAngle();
                angle.Set(0, -20, 0);
                this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
            }
            this.treeViewCatalogTree.ExpandAll();


            // 加载FeatureDataSet对应的LogicGroupTree到界面控件
            nodekeyMap = new Hashtable();
            byte[] bb = GetLogicTreeContent(dataset);
            if (bb != null)
            {
                string strContent = System.Text.Encoding.UTF8.GetString(bb).Trim();
                ShowCurDataSet(strContent);
            }
            // 删除回收站及其子节点
            foreach (TreeNode node in this.treeViewLogicTree.Nodes[0].Nodes)
            {
                if (node.Text.Equals("回收站"))
                {
                    this.treeViewLogicTree.Nodes.Remove(node);
                }
            }

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "ImportModel.html";
            }

            CommonEntity.RenderEntity = this.axRenderControl1;
            CommonEntity.FormEntity   = this;
        }
예제 #16
0
        /// <summary>
        /// 初始化
        /// </summary>
        private void init()
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            // Unknown
            this.axRenderControl1.Initialize(true, ps);
            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 平面坐标系
            //string wkt = @"PROJCS['Beijing_1954_3_Degree_GK_CM_102E',GEOGCS['GCS_Beijing_1954',DATUM['D_Beijing_1954',SPHEROID['Krasovsky_1940',6378245.0,298.3]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Gauss_Kruger'],PARAMETER['False_Easting',500000],PARAMETER['False_Northing',0],PARAMETER['Central_Meridian',102],PARAMETER['Scale_Factor',1],PARAMETER['Latitude_Of_Origin',0],UNIT['metre',1]]";
            //this.axRenderControl1.Initialize2(wkt, ps);
            // 球面1
            //this.axRenderControl1.Initialize(false, ps);
            // 球面2
            //IGeographicCRS crs = new CRSFactory().CreateWGS84();
            //this.axRenderControl1.Initialize2(crs.AsWKT(), ps);

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            #region 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                datasetCRS = dataset.SpatialReference;
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }
            #endregion 加载FDB场景

            this.axRenderControl1.Camera.FlyTime = 0;
            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "ParticleEffect.html";
            }
        }
예제 #17
0
파일: MainForm.cs 프로젝트: batuZ/Samples
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            this.axRenderControl1.Camera.FlyTime = 0;

            // 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\IFC.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                IFeatureClass        fc         = dataset.OpenFeatureClass(fcnames[0]);
                IFieldInfoCollection fieldinfos = fc.GetFields();
                for (int i = 0; i < fieldinfos.Count; i++)
                {
                    IFieldInfo fieldinfo = fieldinfos.Get(i);
                    if (null == fieldinfo)
                    {
                        continue;
                    }
                    IGeometryDef geometryDef = fieldinfo.GeometryDef;
                    if (null == geometryDef)
                    {
                        continue;
                    }
                    ISimpleGeometryRender geoRender = new SimpleGeometryRender();
                    geoRender.RenderGroupField = "ParentObjectId";
                    layer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, fieldinfo.Name, null, geoRender, rootId);
                    IEnvelope env = geometryDef.Envelope;
                    if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                        env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                    {
                        continue;
                    }
                    IEulerAngle angle = new EulerAngle();
                    angle.Set(0, -20, 0);
                    this.axRenderControl1.Camera.LookAt(env.Center, 100, angle);

                    Hashtable   cusData = fc.CustomData.AsHashtable();
                    IEnumerator etor    = cusData.Keys.GetEnumerator();
                    etor.MoveNext();
                    string strXML = (string)cusData[etor.Current];
                    ShowIFCTree(strXML);
                    break;
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "IfcTree.html";
            }
        }
예제 #18
0
        public static HashSet <string> GetValveIdsByFCGuid(string fcGuid)
        {
            if (ValveManager.Instance.Exists(fcGuid))
            {
                return(ValveManager.Instance.GetValveIds(fcGuid));
            }
            if (DF3DPipeCreateApp.App.PipeLib == null)
            {
                return(null);
            }
            IFeatureClass fc     = null;
            IQueryFilter  filter = null;
            IFdeCursor    cursor = null;
            IRowBuffer    buffer = null;

            try
            {
                if (dictFC.ContainsKey(fcGuid) && dictFC[fcGuid] != null)
                {
                    fc = dictFC[fcGuid];
                }
                else
                {
                    IFeatureDataSet fds = DF3DPipeCreateApp.App.PipeLib.OpenFeatureDataset("DataSet_GEO_Actuality");
                    if (fds == null)
                    {
                        return(null);
                    }
                    string[] fcNames = fds.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                    if (fcNames == null)
                    {
                        return(null);
                    }
                    foreach (string fcName in fcNames)
                    {
                        IFeatureClass fcTemp = fds.OpenFeatureClass(fcName);
                        if (fcTemp.GuidString == fcGuid)
                        {
                            fc = fcTemp;
                            break;
                        }
                    }
                    if (fc == null)
                    {
                        return(null);
                    }
                    FacilityClass fac = FacilityClassManager.Instance.GetFacilityClassByName("PipeNode");
                    if (fac == null)
                    {
                        return(null);
                    }
                    DFDataConfig.Class.FieldInfo fi = fac.GetFieldInfoBySystemName("Additional");
                    if (fi == null)
                    {
                        return(null);
                    }

                    filter = new QueryFilterClass
                    {
                        SubFields   = "oid," + fi.Name,
                        WhereClause = fi.Name + " LIKE '%阀%'"//改
                    };
                    int count = fc.GetCount(filter);
                    if (count == 0)
                    {
                        return(null);
                    }
                    cursor = fc.Search(filter, false);
                    HashSet <string> hsRes = new HashSet <string>();
                    while ((buffer = cursor.NextRow()) != null)
                    {
                        hsRes.Add(fc.GuidString + "_" + buffer.GetValue(0).ToString());
                    }
                    ValveManager.Instance.Add(fcGuid, hsRes);
                    return(hsRes);
                }
                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
                if (buffer != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(buffer);
                    buffer = null;
                }
            }
        }
예제 #19
0
파일: MainForm.cs 프로젝트: batuZ/Samples
        void init()
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 注册出图事件
            this.axRenderControl1.RcPictureExportBegin += new _IRenderControlEvents_RcPictureExportBeginEventHandler(axRenderControl1_RcPictureExportBegin);

            this.axRenderControl1.RcPictureExporting += new _IRenderControlEvents_RcPictureExportingEventHandler(axRenderControl1_RcPictureExporting);

            this.axRenderControl1.RcPictureExportEnd += new _IRenderControlEvents_RcPictureExportEndEventHandler(axRenderControl1_RcPictureExportEnd);

            // 注册相机“返回”和“前进”事件
            this.axRenderControl1.RcCameraUndoRedoStatusChanged += new _IRenderControlEvents_RcCameraUndoRedoStatusChangedEventHandler(axRenderControl1_RcCameraUndoRedoStatusChanged);
            _rcCameraUndoRedo = new _IRenderControlEvents_RcCameraUndoRedoStatusChangedEventHandler(axRenderControl1_RcCameraUndoRedoStatusChanged);

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            // 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;

            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        env = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }

            // 加载动画导航
            BindingSource bindingSource1 = new BindingSource();

            {
                string tmpXMLPath = (strMediaPath + @"\xml\CameraTour_1.xml");
                tour = this.axRenderControl1.ObjectManager.CreateCameraTour(rootId);
                if (File.Exists(tmpXMLPath))
                {
                    StreamReader sr        = new StreamReader(tmpXMLPath);
                    string       xmlstring = "";
                    string       line      = sr.ReadLine();
                    while (!string.IsNullOrEmpty(line))
                    {
                        xmlstring += line;
                        line       = sr.ReadLine();
                    }
                    sr.Close();
                    tour.FromXml(xmlstring);
                }
                bindingSource1.Add(new Knight("CameraTour_1", tour));
            }
            {
                string tmpXMLPath = (strMediaPath + @"\xml\CameraTour_2.xml");
                tour = this.axRenderControl1.ObjectManager.CreateCameraTour(rootId);
                if (File.Exists(tmpXMLPath))
                {
                    StreamReader sr        = new StreamReader(tmpXMLPath);
                    string       xmlstring = "";
                    string       line      = sr.ReadLine();
                    while (!string.IsNullOrEmpty(line))
                    {
                        xmlstring += line;
                        line       = sr.ReadLine();
                    }
                    sr.Close();
                    tour.FromXml(xmlstring);
                }
                bindingSource1.Add(new Knight("CameraTour_2", tour));
            }

            dataGridView1.DataSource                    = bindingSource1;
            dataGridView1.Columns[1].Visible            = false;
            this.btnPause.Enabled                       = false;
            this.btnStop.Enabled                        = false;
            this.toolStripComboBoxWeather.SelectedIndex = 0;

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "HelloWorld.html";
            }
        }
예제 #20
0
        // 公共方法
        void FeatureLayerVisualize(IConnectionInfo ci, bool needfly, string sourceName)
        {
            try
            {
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    _featureClass = fc;
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = !needfly;

            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    IFieldInfoCollection fieldinfos  = fc.GetFields();
                    IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                    IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                    IEnvelope            env         = geometryDef.Envelope;
                    if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                        env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                    {
                        continue;
                    }

                    // 相机飞入
                    if (!hasfly)
                    {
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }
        }
예제 #21
0
        public static void AddAndVisualizeBaseData(IConnectionInfo ci, string geoColumnName, TreeList parentTree, bool bNeedFly = false, bool bTempData = true)
        {
            try
            {
                if (ci == null || parentTree == null)
                {
                    return;
                }
                if (bTempData)
                {
                    WaitForm.Start("正在加载三维数据,请稍后...", "提示");
                }

                DF3DApplication app = DF3DApplication.Application;
                if (app == null || app.Current3DMapControl == null)
                {
                    return;
                }
                AxRenderControl    d3        = app.Current3DMapControl;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                if (!dsFactory.HasDataSource(ci))
                {
                    return;
                }
                IDataSource ds = dsFactory.OpenDataSource(ci);
                if (ds == null)
                {
                    return;
                }
                //TreeNodeDatabase tnDatabase = new TreeNodeDatabase()
                //{
                //    Name = ci.ConnectionType == gviConnectionType.gviConnectionFireBird2x ? System.IO.Path.GetFileNameWithoutExtension(ci.Database) : ci.Database,
                //    CustomValue = ds,
                //    Temp = bTempData
                //};
                //tnDatabase.OwnNode = parentTree.AppendNode(new object[] { tnDatabase.Name }, (TreeListNode)null);
                //tnDatabase.Visible = true;

                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                for (int j = 0; j < setnames.Length; j++)
                {
                    IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[j]);

                    string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                    if (fcnames.Length == 0)
                    {
                        continue;
                    }

                    TreeNodeDataset tnDataset = new TreeNodeDataset()
                    {
                        Name        = dataset.Alias,
                        CustomValue = dataset,
                        Temp        = bTempData
                    };
                    tnDataset.OwnNode = parentTree.AppendNode(new object[] { tnDataset.Name }, (TreeListNode)null);
                    //tnDatabase.Add(tnDataset);

                    foreach (string name in fcnames)
                    {
                        IFeatureClass fc = dataset.OpenFeatureClass(name);
                        if (fc == null)
                        {
                            continue;
                        }
                        TreeNodeFeatureClass tnFeatureClass = new TreeNodeFeatureClass(fc.GuidString)
                        {
                            Name        = fc.AliasName,
                            CustomValue = fc,
                            Temp        = bTempData
                        };
                        tnDataset.Add(tnFeatureClass);

                        IFieldInfoCollection fieldinfos = fc.GetFields();
                        if (fieldinfos == null)
                        {
                            continue;
                        }
                        int index = fieldinfos.IndexOf(geoColumnName);
                        if (index == -1)
                        {
                        }
                        else
                        {
                            IFieldInfo fieldinfo = fieldinfos.Get(index);
                            if (null == fieldinfo)
                            {
                                continue;
                            }
                            IGeometryDef  geometryDef = fieldinfo.GeometryDef;
                            IFeatureLayer fl          = null;
                            if (null != geometryDef)
                            {
                                fl = d3.ObjectManager.CreateFeatureLayer(fc, fieldinfo.Name, null, null, d3.ProjectTree.RootID);
                                tnFeatureClass.SetVisualFeatureLayer(fl);
                                switch (geometryDef.GeometryColumnType)
                                {
                                case gviGeometryColumnType.gviGeometryColumnModelPoint:
                                    tnFeatureClass.Visible    = true;
                                    tnFeatureClass.ImageIndex = 3;
                                    break;

                                case gviGeometryColumnType.gviGeometryColumnPOI:
                                case gviGeometryColumnType.gviGeometryColumnPoint:
                                    tnFeatureClass.Visible    = false;
                                    tnFeatureClass.ImageIndex = 4;
                                    break;

                                case gviGeometryColumnType.gviGeometryColumnPolyline:
                                    tnFeatureClass.Visible    = false;
                                    tnFeatureClass.ImageIndex = 5;
                                    break;

                                case gviGeometryColumnType.gviGeometryColumnPolygon:
                                    tnFeatureClass.Visible    = false;
                                    tnFeatureClass.ImageIndex = 6;
                                    break;
                                }
                            }

                            // 加入管理类
                            if (!bTempData && fl != null)
                            {
                                DF3DFeatureClass dfFC = new DF3DFeatureClass(fc);
                                dfFC.SetFeatureLayer(fl);
                                dfFC.SetTreeLayer(tnFeatureClass);
                                Render3D.Instance.SetRender(tnFeatureClass, dfFC);
                                DF3DFeatureClassManager.Instance.Add(dfFC);
                            }


                            if (fl != null && bNeedFly)
                            {
                                IEulerAngle angle = new EulerAngle();
                                angle.Set(0, -20, 0);
                                d3.Camera.SetCamera(fl.Envelope.Center, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                                bNeedFly = false;
                            }
                        }
                    }
                    tnDataset.CollapseAll();
                }
                //tnDatabase.CollapseAll();

                //ds.Close();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("加载三维数据失败,请检查数据是否被占用或链接是否有错误。", "提示");
                LoggingService.Error("加载三维数据失败:" + ex.Message);
            }
            finally
            {
                if (bTempData)
                {
                    WaitForm.Stop();
                }
            }
        }
예제 #22
0
파일: MainForm.cs 프로젝트: batuZ/Samples
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            // 加载FDB场景
            //try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset = ds.OpenFeatureDataset(setnames[0]);
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            //catch (COMException ex)
            //{
            //    System.Diagnostics.Trace.WriteLine(ex.Message);
            //    return;
            //}

            // CreateFeautureLayer
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, rootId);
                }
            }

            IPoint position = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ);

            position.SetCoords(15371.768457028507, 35951.723472296966, 20.9338220668297, 0, 0);
            position.SpatialCRS = dataset.SpatialReference;
            IEulerAngle angle = new EulerAngle();

            angle.Set(11.76, -19.26, 0);
            this.axRenderControl1.Camera.SetCamera2(position, angle, gviSetCameraFlags.gviSetCameraNoFlags);

            //获取默认的静态贴图
            //try
            {
                resManager = dataset as IResourceManager;
                imgStatic  = resManager.GetImage("paizi6");
            }
            //catch (System.Exception ex)
            //{
            //    if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
            //        MessageBox.Show("需要标准runtime授权");
            //    else
            //        MessageBox.Show(ex.Message);
            //}

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "DynamicImage.html";
            }
        }
예제 #23
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            // 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\PIPE.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset = ds.OpenFeatureDataset(setnames[0]);
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, null, null, rootId);
                }
            }

            IPoint position = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ);

            position.SetCoords(506308.31579040177, 314272.281405516, 3.2581421811509275, 0, 0);
            position.SpatialCRS = dataset.SpatialReference;
            IEulerAngle angle = new EulerAngle();

            angle.Set(66.16, -14.2, 0);
            this.axRenderControl1.Camera.SetCamera2(position, angle, gviSetCameraFlags.gviSetCameraNoFlags);

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "DynamicPipe.html";
            }
        }
예제 #24
0
        private void init()
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\7_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\7_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\7_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\7_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\7_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\7_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            #region 加载shp
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionShapeFile;
                string tmpFDBPath = (strMediaPath + @"\shp\road\road.shp");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                datasetCRS = dataset.SpatialReference;
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        env = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -20, 0);
                        IPoint point = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                        point.Position   = env.Center;
                        point.SpatialCRS = fc.FeatureDataSet.SpatialReference;
                        this.axRenderControl1.Camera.LookAt2(point, 1000, angle);
                    }
                    hasfly = true;
                }
            }
            #endregion
        }
예제 #25
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            this.axRenderControl1.Camera.FlyTime = 1;

            #region 加载SDKDEMO场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                //遍历FeatureClass
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);
                    flayerList.Add(featureLayer);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -90, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }
            #endregion

            //注册地形
            string tmpTedPath = (strMediaPath + @"\terrain\SingaporePlanarTerrain.ted");
            this.axRenderControl1.Terrain.RegisterTerrain(tmpTedPath, "");

            if (player == null)
            {
                player = this.axRenderControl1.HeatMapPlayer;
            }

            // 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\HeatMap.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);

                    if (fc.HasTemporal())
                    {
                        ITemporalManager tm    = fc.TemporalManager;
                        DateTime[]       times = tm.GetKeyDatetimes();
                        for (int i = 0; i < times.Length; i++)
                        {
                            if (keyDatetimesList.Contains(times[i]))
                            {
                                continue;
                            }
                            keyDatetimesList.Add(times[i]);
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // 设置时间轴
            if (keyDatetimesList.Count == 0)
            {
                this.cbKeyTimes.Enabled = false;
                this.btnPlay.Enabled    = false;
                this.btnPause.Enabled   = false;
                this.btnStop.Enabled    = false;
            }
            else
            {
                keyDatetimesList.Sort();
                for (int t = 0; t < keyDatetimesList.Count; t++)
                {
                    DateTime d = keyDatetimesList[t];
                    cbKeyTimes.Items.Add(d);
                }
            }

            // CreateFeautureLayer
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    heatmap = this.axRenderControl1.ObjectManager.CreateHeatMap(
                        fc, geoName, "HotValue", rootId);
                    if (heatmap == null)
                    {
                        continue;
                    }
                    this.txtMinValue.Text = heatmap.MinHeatValue.ToString();
                    this.txtMaxValue.Text = heatmap.MaxHeatValue.ToString();
                }
            }

            //设置curLayer的时刻为最新时刻
            if (keyDatetimesList.Count > 0)
            {
                DateTime dmax = (keyDatetimesList[keyDatetimesList.Count - 1]);
                player.SetTime(dmax);

                //设置时间轴为最小
                cbKeyTimes.SelectedIndex = keyDatetimesList.Count - 1;
            }

            //测试自定义颜色
            //System.Drawing.Color[] colors = new System.Drawing.Color[2];
            //colors[0] = System.Drawing.Color.White;
            //colors[1] = System.Drawing.Color.Gray;
            //bool suc = player.SetColor(colors, 2);
            //if(suc)
            //{
            //    System.Drawing.Color[] colorvec;
            //    byte c;
            //    bool suc2 = player.GetColor(out colorvec, out c);
            //    if (suc2)
            //        this.Text = c.ToString();
            //}

            this.cbShowHeatMap.Checked      = true;
            this.cbShowFeatureLayer.Checked = true;

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "Temporal.html";
            }
        }
예제 #26
0
        public void Init()
        {
            try
            {
                this._ds = DF3DPipeCreateApp.App.PipeLib;
                if (this._ds == null)
                {
                    this.Enabled = false; return;
                }
                this.treeList1.ClearNodes();
                if (!this._init3DControl)
                {
                    this._init3DControl = Init3DControl();
                }
                if (!this._init3DControl)
                {
                    this.Enabled = false; return;
                }
                if (this._init3DControl)
                {
                    foreach (Guid guid in allFLGuid)
                    {
                        this.AxRenderControl3D.ObjectManager.DeleteObject(guid);
                    }
                    this.allFLGuid.Clear();
                    foreach (Guid guid in allTLGuid)
                    {
                        this.AxRenderControl3D.ObjectManager.DeleteObject(guid);
                    }
                    this.allTLGuid.Clear();

                    this._dictFeatureClass.Clear();

                    WaitForm.Start("正在加载数据...", "请稍后");

                    bool     bHaveFly = false;
                    Guid     gd       = Guid.NewGuid();
                    string[] fdsNames = this._ds.GetFeatureDatasetNames();
                    if (fdsNames == null)
                    {
                        return;
                    }
                    foreach (string fdsName in fdsNames)
                    {
                        IFeatureDataSet fds = this._ds.OpenFeatureDataset(fdsName);
                        if (fds == null)
                        {
                            continue;
                        }
                        TreeListNode fdsNode = this.treeList1.AppendNode(new object[] { fds.Name, fds }, null);
                        fdsNode.StateImageIndex = 0;
                        string[] fcNames = fds.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                        if (fcNames == null)
                        {
                            continue;
                        }
                        foreach (string fcName in fcNames)
                        {
                            IFeatureClass fc = fds.OpenFeatureClass(fcName);
                            if (fc == null)
                            {
                                continue;
                            }
                            this._dictFeatureClass[fc.Guid] = fc;
                            string       name   = string.IsNullOrEmpty(fc.AliasName) ? fc.Name : fc.AliasName;
                            TreeListNode fcNode = this.treeList1.AppendNode(new object[] { name, fc }, fdsNode);
                            fcNode.StateImageIndex = 1;
                            IFieldInfoCollection fiCol = fc.GetFields();
                            int indexGeo = fiCol.IndexOf("Geometry");
                            if (indexGeo != -1)
                            {
                                IFieldInfo fi = fiCol.Get(indexGeo);
                                if (fi.GeometryDef != null)
                                {
                                    IFeatureLayer fl = this.AxRenderControl3D.ObjectManager.CreateFeatureLayer(fc, fi.Name, null, null, this.AxRenderControl3D.ProjectTree.RootID);
                                    if (fl == null)
                                    {
                                        continue;
                                    }
                                    fl.MaxVisibleDistance = 100000;
                                    TreeListNode flNode = this.treeList1.AppendNode(new object[] { fi.Name, fl }, fcNode);
                                    flNode.StateImageIndex = 2;
                                    if (fi.GeometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnModelPoint)
                                    {
                                        fl.VisibleMask   = gviViewportMask.gviViewAllNormalView;
                                        fl.ForceCullMode = true;
                                        fl.CullMode      = Gvitech.CityMaker.Resource.gviCullFaceMode.gviCullNone;
                                        flNode.Checked   = true;
                                    }
                                    else
                                    {
                                        fl.VisibleMask = gviViewportMask.gviViewNone;
                                        flNode.Checked = false;
                                    }
                                    bHaveFly = true;
                                    gd       = fl.Guid;
                                    this.allFLGuid.Add(fl.Guid);
                                }
                            }
                            int indexShp = fiCol.IndexOf("Shape");
                            if (indexShp != -1)
                            {
                                IFieldInfo fi = fiCol.Get(indexShp);
                                if (fi.GeometryDef != null)
                                {
                                    IFeatureLayer fl = this.AxRenderControl3D.ObjectManager.CreateFeatureLayer(fc, fi.Name, null, null, this.AxRenderControl3D.ProjectTree.RootID);
                                    if (fl == null)
                                    {
                                        continue;
                                    }
                                    fl.MaxVisibleDistance = 100000;
                                    TreeListNode flNode = this.treeList1.AppendNode(new object[] { fi.Name, fl }, fcNode);
                                    flNode.StateImageIndex = 2;
                                    if (fi.GeometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnModelPoint)
                                    {
                                        fl.VisibleMask = gviViewportMask.gviViewAllNormalView;
                                        flNode.Checked = true;
                                    }
                                    else
                                    {
                                        fl.VisibleMask = gviViewportMask.gviViewNone;
                                        flNode.Checked = false;
                                    }
                                    bHaveFly = true;
                                    gd       = fl.Guid;
                                    this.allFLGuid.Add(fl.Guid);
                                }
                            }
                            int indexFoot = fiCol.IndexOf("FootPrint");
                            if (indexFoot != -1)
                            {
                                IFieldInfo fi = fiCol.Get(indexFoot);
                                if (fi.GeometryDef != null)
                                {
                                    IFeatureLayer fl = this.AxRenderControl3D.ObjectManager.CreateFeatureLayer(fc, fi.Name, null, null, this.AxRenderControl3D.ProjectTree.RootID);
                                    fl.MaxVisibleDistance = 100000;
                                    if (fl == null)
                                    {
                                        continue;
                                    }
                                    TreeListNode flNode = this.treeList1.AppendNode(new object[] { fi.Name, fl }, fcNode);
                                    flNode.StateImageIndex = 2;
                                    if (fi.GeometryDef.GeometryColumnType == gviGeometryColumnType.gviGeometryColumnModelPoint)
                                    {
                                        fl.VisibleMask = gviViewportMask.gviViewAllNormalView;
                                        flNode.Checked = true;
                                    }
                                    else
                                    {
                                        fl.VisibleMask = gviViewportMask.gviViewNone;
                                        flNode.Checked = false;
                                    }
                                    bHaveFly = true;
                                    gd       = fl.Guid;
                                    this.allFLGuid.Add(fl.Guid);
                                }
                            }
                        }
                    }
                    this.treeList1.ExpandAll();
                    if (bHaveFly)
                    {
                        this.AxRenderControl3D.Camera.FlyToObject(gd, gviActionCode.gviActionFlyTo);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                WaitForm.Stop();
            }
        }
예제 #27
0
        // 公共方法
        void FeatureLayerVisualize(IConnectionInfo ci, bool needfly, string sourceName,
                                   ITextRender textRender, IGeometryRender geoRender)
        {
            IDataSourceFactory dsFactory = null;
            IDataSource        ds        = null;
            IFeatureDataSet    dataset   = null;

            try
            {
                dsFactory = new DataSourceFactory();
                ds        = dsFactory.OpenDataSource(ci);
                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                dataset = ds.OpenFeatureDataset(setnames[0]);
                string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }

                // CreateFeautureLayer
                bool hasfly = !needfly;
                foreach (IFeatureClass fcInMap in fcMap.Keys)
                {
                    List <string> geoNames = (List <string>)fcMap[fcInMap];
                    foreach (string geoName in geoNames)
                    {
                        IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                            fcInMap, geoName, textRender, geoRender, rootId);

                        // 设置featureLayer组可见
                        if (!geoRender.RenderGroupField.Equals(""))
                        {
                            SetGroupVisiable(dataset, featureLayer);
                        }

                        // 添加节点到界面控件上
                        myListNode item = new myListNode(string.Format("{0}_{1}_{2}", sourceName, fcInMap.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer);
                        item.Checked = true;
                        listView1.Items.Add(item);
                        layerFcMap.Add(featureLayer, fcInMap);

                        IFieldInfoCollection fieldinfos  = fcInMap.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        layerEnvelopeMap.Add(featureLayer, env);
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }

                        // 相机飞入
                        if (!hasfly)
                        {
                            angle.Set(0, -20, 0);
                            this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                        }
                        hasfly = true;
                    }
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
            catch (System.Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.Message);
                return;
            }
            finally
            {
                if (dsFactory != null)
                {
                    //Marshal.ReleaseComObject(dsFactory);
                    dsFactory = null;
                }
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                //if (fc != null)
                //{
                //    //Marshal.ReleaseComObject(fc);
                //    fc = null;
                //}
            }
        }
예제 #28
0
        public MainForm()
        {
            InitializeComponent();

            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;
            this.axRenderControl1.Camera.FlyTime = 1;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                //string tmpSkyboxPath = strMediaPath + @"\skybox";
                //ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                //skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                //skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                //skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                //skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                //skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                //skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            #region 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\polyline.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    ISimpleTextRender tr = new SimpleTextRender();
                    tr.Expression       = "$(oid)";
                    tr.MinimizeOverlap  = true;
                    tr.DynamicPlacement = true;
                    ITextSymbol ts = new TextSymbol();
                    tr.Symbol    = ts;
                    featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(fc, geoName, tr, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 600, angle);
                    }
                    hasfly = true;
                }
            }
            #endregion 加载FDB场景

            #region 查询所有值
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                DataTable dt = CreateDataTable(fc);
                pipeMap = new Hashtable();
                GetResultSet(fc, null, dt);
                this.dataGridViewPolyline.DataSource = dt;
            }
            #endregion

            this.comboBoxPlayMode.SelectedIndex = 2;

            this.axRenderControl1.InteractMode          = gviInteractMode.gviInteractSelect;
            this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectRenderPipeLine;
            this.axRenderControl1.MouseSelectMode       = gviMouseSelectMode.gviMouseSelectDrag;
            //this.axRenderControl1.RcMouseClickSelect += AxRenderControl1_RcMouseClickSelect;
            this.axRenderControl1.RcMouseDragSelect += AxRenderControl1_RcMouseDragSelect;

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "RenderPipeLine.html";
            }
        }
예제 #29
0
        /// <summary>
        /// 初始化
        /// </summary>
        private void init()
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");

                skybox = this.axRenderControl1.ObjectManager.GetSkyBox(1);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\2_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\2_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\2_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\2_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\2_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\2_UP.jpg");

                skybox = this.axRenderControl1.ObjectManager.GetSkyBox(2);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\04_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\04_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\04_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\04_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\04_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\04_UP.jpg");

                skybox = this.axRenderControl1.ObjectManager.GetSkyBox(3);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\9_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\9_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\9_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\9_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\9_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\9_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            #region 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }
                fcMap = new Hashtable(fcnames.Length);
                foreach (string name in fcnames)
                {
                    IFeatureClass fc = dataset.OpenFeatureClass(name);
                    // 找到空间列字段
                    List <string>        geoNames   = new List <string>();
                    IFieldInfoCollection fieldinfos = fc.GetFields();
                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        IGeometryDef geometryDef = fieldinfo.GeometryDef;
                        if (null == geometryDef)
                        {
                            continue;
                        }
                        geoNames.Add(fieldinfo.Name);
                    }
                    fcMap.Add(fc, geoNames);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }

            // CreateFeautureLayer
            bool hasfly = false;
            foreach (IFeatureClass fc in fcMap.Keys)
            {
                List <string> geoNames = (List <string>)fcMap[fc];
                foreach (string geoName in geoNames)
                {
                    if (!geoName.Equals("Geometry"))
                    {
                        continue;
                    }

                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!hasfly)
                    {
                        IFieldInfoCollection fieldinfos  = fc.GetFields();
                        IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf(geoName));
                        IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                        IEnvelope            env         = geometryDef.Envelope;
                        if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 &&
                                            env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0))
                        {
                            continue;
                        }
                        IEulerAngle angle = new EulerAngle();
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }
            #endregion 加载FDB场景

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "HideSelectedArea.html";
            }

            // 注册控件拾取事件
            this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect);

            this.axRenderControl1.RcMouseDragSelect += new _IRenderControlEvents_RcMouseDragSelectEventHandler(axRenderControl1_RcMouseDragSelect);


            this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectFeatureLayer;
            this.axRenderControl1.InteractMode          = gviInteractMode.gviInteractSelect;
            this.axRenderControl1.MouseSelectMode       = gviMouseSelectMode.gviMouseSelectClick | gviMouseSelectMode.gviMouseSelectDrag;
        }
예제 #30
0
파일: MainForm.cs 프로젝트: batuZ/Samples
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            // 初始化RenderControl控件
            IPropertySet ps = new PropertySet();

            ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL);
            this.axRenderControl1.Initialize(true, ps);
            this.axRenderControl1.Camera.FlyTime = 1;

            rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID;

            // 设置天空盒

            if (System.IO.Directory.Exists(strMediaPath))
            {
                string  tmpSkyboxPath = strMediaPath + @"\skybox";
                ISkyBox skybox        = this.axRenderControl1.ObjectManager.GetSkyBox(0);
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg");
                skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg");
            }
            else
            {
                MessageBox.Show("请不要随意更改SDK目录名");
                return;
            }

            #region 加载FDB场景
            try
            {
                IConnectionInfo ci = new ConnectionInfo();
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                string tmpFDBPath = (strMediaPath + @"\MultiSpatialColumns.FDB");
                ci.Database = tmpFDBPath;
                IDataSourceFactory dsFactory = new DataSourceFactory();
                IDataSource        ds        = dsFactory.OpenDataSource(ci);
                string[]           setnames  = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]);
                string[]        fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                if (fcnames.Length == 0)
                {
                    return;
                }

                // 仅仅加载“建筑”要素类
                _featureClass = dataset.OpenFeatureClass("建筑");

                {
                    // 用名为"Geometry"的空间列创建模型FeautureLayer
                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(_featureClass, "Geometry", null, null, rootId);
                    // 添加节点到界面控件上
                    myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "ModelPoint", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer);
                    item.Checked = true;
                    listView1.Items.Add(item);
                }
                {
                    //用名为"Surface"的空间列创建模型FeautureLayer
                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(_featureClass, "Surface", null, null, rootId);
                    // 添加节点到界面控件上
                    myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "Surface", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer);
                    item.Checked = true;
                    listView1.Items.Add(item);
                }
                {
                    //用名为"Polygon"的空间列创建模型FeautureLayer
                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(_featureClass, "Polygon", null, null, rootId);
                    // 添加节点到界面控件上
                    myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "Polygon", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer);
                    item.Checked = true;
                    listView1.Items.Add(item);
                }
                //{
                //    //用名为"Point"的空间列创建模型FeautureLayer
                //    IFeatureLayer featureLayer = this.axRenderControl1.FeatureLayerManager.CreateFeatureLayer(_featureClass, "Point", null, null);
                //    // 添加节点到界面控件上
                //    myListNode item = new myListNode(string.Format("{0}_{1}_{2}", "Point", _featureClass.Name, featureLayer.MaxVisibleDistance.ToString()), featureLayer);
                //    item.Checked = true;
                //    listView1.Items.Add(item);
                //}

                IFieldInfoCollection fieldinfos  = _featureClass.GetFields();
                IFieldInfo           fieldinfo   = fieldinfos.Get(fieldinfos.IndexOf("Geometry"));
                IGeometryDef         geometryDef = fieldinfo.GeometryDef;
                IEnvelope            env         = geometryDef.Envelope;
                IEulerAngle          angle       = new EulerAngle();
                angle.Set(0, -20, 0);
                this.axRenderControl1.Camera.LookAt(env.Center, 400, angle);
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
            #endregion

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "MultiSpatialColumns.html";
            }
        }