예제 #1
0
        private void LoadDynamicObjectAndLineFromFile()
        {
            ICameraTour tour     = null;
            string      tourPath = (strMediaPath + @"\xml\CameraTour_2.xml");

            if (File.Exists(tourPath))
            {
                StreamReader sr        = new StreamReader(tourPath);
                string       xmlstring = sr.ReadToEnd();
                sr.Close();
                tour = this.axRenderControl1.ObjectManager.CreateCameraTour(rootId);
                tour.FromXml(xmlstring);
            }
            if (tour == null)
            {
                MessageBox.Show("xml文件读取失败");
            }

            dynamicObject.CrsWKT = tour.CrsWKT;
            point.SpatialCRS     = new CRSFactory().CreateFromWKT(tour.CrsWKT) as ISpatialCRS;
            line.SpatialCRS      = new CRSFactory().CreateFromWKT(tour.CrsWKT) as ISpatialCRS;

            for (int i = 0; i < tour.WaypointsNumber; i++)
            {
                double            duration;
                gviCameraTourMode mode;
                tour.GetWaypoint(i, out position, out angle, out duration, out mode);
                dynamicObject.AddWaypoint(position, 10);

                point.Position = position;
                if (line.PointCount == 0)
                {
                    line.StartPoint = point;
                }
                else
                {
                    line.AddPointAfter(i - 1, point);
                }
            }

            ICurveSymbol cur = new CurveSymbol();

            cur.Color = System.Drawing.Color.Yellow;
            cur.Width = -2;
            rline     = this.axRenderControl1.ObjectManager.CreateRenderPolyline(line, cur, rootId);
        }
예제 #2
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";
            }
        }
예제 #3
0
        private void btnImportFromXML_Click(object sender, EventArgs e)
        {
            OpenFileDialog od = new OpenFileDialog();

            od.Filter = "XML文件|*.xml";
            if (System.IO.Directory.Exists(strMediaPath))
            {
                od.InitialDirectory = strMediaPath + @"\xml";
            }
            od.RestoreDirectory = true;
            if (od.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(od.FileName))
                {
                    StreamReader sr        = new StreamReader(od.FileName);
                    string       xmlstring = sr.ReadToEnd();
                    sr.Close();
                    tour = null;
                    tour = this.axRenderControl1.ObjectManager.CreateCameraTour(rootId);
                    tour.FromXml(xmlstring);

                    if (tour.WaypointsNumber > 0)
                    {
                        //初始化节点表格
                        dt = new DataTable();
                        DataColumn dc0 = new DataColumn("index", typeof(int));
                        DataColumn dc1 = new DataColumn("x", typeof(double));
                        DataColumn dc2 = new DataColumn("y", typeof(double));
                        DataColumn dc3 = new DataColumn("z", typeof(double));
                        DataColumn dc4 = new DataColumn("heading", typeof(double));
                        DataColumn dc5 = new DataColumn("tilt", typeof(double));
                        DataColumn dc6 = new DataColumn("roll", typeof(double));
                        DataColumn dc7 = new DataColumn("duration", typeof(double));
                        DataColumn dc8 = new DataColumn("mode", typeof(string));
                        dt.Columns.AddRange(new DataColumn[] { dc0, dc1, dc2, dc3, dc4, dc5, dc6, dc7, dc8 });
                        this.dataGridView1.DataSource = dt;

                        for (int i = 0; i < tour.WaypointsNumber; i++)
                        {
                            double            duration;
                            gviCameraTourMode mode;
                            tour.GetWaypoint(i, out position, out angle, out duration, out mode);

                            //将值写入表格
                            DataRow dr = dt.NewRow();
                            dr[0] = i;
                            dr[1] = position.X;
                            dr[2] = position.Y;
                            dr[3] = position.Z;
                            dr[4] = angle.Heading;
                            dr[5] = angle.Tilt;
                            dr[6] = angle.Roll;
                            dr[7] = duration;
                            dr[8] = getModeString(mode);
                            dt.Rows.Add(dr);
                        }
                        this.dataGridView1.Update();

                        //更新Time滑动条最大值
                        decimal mathRound = Math.Round((decimal)tour.TotalTime, 2);
                        this.trackBarTime.Maximum = int.Parse(((double)mathRound * 100.0).ToString());
                    }
                }
            }
        }