Exemple #1
0
 public ParticleEffect()
 {
     ImageName                = (strMediaPath + @"\png\Partial.png");
     EmissionMaxMoveSpeed     = 8;
     EmissionMinMoveSpeed     = 5;
     EmissionMinRate          = 64;
     EmissionMaxRate          = 90;
     ParticleMaxLifeTime      = 1.8;
     ParticleMinLifeTime      = 1;
     ParticleBillboardType    = gviParticleBillboardType.gviParticleBillboardOrientedCamera;
     WindDirection            = 0;
     WindAcceleration         = 0.2;
     ParticleBirthColor       = ColorHelper.UintToColor(4294954035);
     ParticleDeathColor       = ColorHelper.UintToColor(16731187);
     emissionMinScaleSpeed    = 0;
     EmissionMaxScaleSpeed    = 0;
     VerticalAcceleration     = 0.8;
     EmissionMaxAngle         = 40;
     EmissionMinAngle         = 0.1;
     EmissionMinParticleSize  = 0.2;
     EmissionMaxParticleSize  = 0.3;
     EmissionMinRotationSpeed = -1;
     EmissionMaxRotationSpeed = 1;
     Damping             = 0.5;
     particleAspectRatio = 1;
     v3.Set(0, 0, 0);
     EmissionDirectionEulerAngle = v3.Heading.ToString() + "," + v3.Tilt.ToString() + "," + v3.Roll.ToString();
 }
Exemple #2
0
 public ComplexParticleEffect()
 {
     EmissionRate     = 1;
     ScalingFactor    = 5;
     WindAcceleration = 0;
     WindDirection    = 0;
     v3.Set(0, 0, 0);
     RotateAngle = v3.Heading.ToString() + "," + v3.Tilt.ToString() + "," + v3.Roll.ToString();
 }
Exemple #3
0
        private void LoadMotionPathAndLineFromFile()
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(Application.StartupPath + @"MotionPath.xml");
            wkt = xmlDoc.SelectSingleNode("root/WKT").InnerText;
            // 指定坐标系与xml里的相同
            motionPath.CrsWKT = xmlDoc.SelectSingleNode("root/WKT").InnerText;
            point.SpatialCRS  = new CRSFactory().CreateFromWKT(motionPath.CrsWKT) as ISpatialCRS;
            line.SpatialCRS   = new CRSFactory().CreateFromWKT(motionPath.CrsWKT) as ISpatialCRS;

            XmlNodeList nodes = xmlDoc.SelectNodes("root/Waypoint");
            int         i     = 0;

            foreach (XmlNode node in nodes)
            {
                double x       = double.Parse(node.SelectSingleNode("X").InnerText);
                double y       = double.Parse(node.SelectSingleNode("Y").InnerText);
                double z       = double.Parse(node.SelectSingleNode("Z").InnerText);
                double heading = double.Parse(node.SelectSingleNode("Heading").InnerText);
                double tilt    = double.Parse(node.SelectSingleNode("Tilt").InnerText);
                double roll    = double.Parse(node.SelectSingleNode("Roll").InnerText);
                double when    = double.Parse(node.SelectSingleNode("When").InnerText);
                position.Set(x, y, z);
                point.Position = position;
                if (line.PointCount == 0)
                {
                    line.StartPoint = point;
                }
                else
                {
                    line.AddPointAfter(i - 1, point);
                }
                i++;
                angle.Set(heading, tilt, roll);
                scale.Set(1, 1, 1);
                motionPath.AddWaypoint2(point, angle, scale, when);
                this.axRenderControl1.ObjectManager.CreateRenderPoint(point, null, rootId);
            }

            ICurveSymbol cur = new CurveSymbol();

            cur.Color = System.Drawing.Color.Red;
            cur.Width = -2;
            rline     = this.axRenderControl1.ObjectManager.CreateRenderPolyline(line, cur, rootId);
        }
Exemple #4
0
        private void ToolStripMenuItemCreateRenderPolyline_Click(object sender, EventArgs e)
        {
            motionPath = this.axRenderControl1.ObjectManager.CreateMotionPath(rootId);

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(Application.StartupPath + @"\MotionPath.xml");
            string wkt = xmlDoc.SelectSingleNode("root/WKT").InnerText;

            motionPath.CrsWKT = wkt;
            IPoint point = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ);

            point.SpatialCRS = new CRSFactory().CreateFromWKT(wkt) as ISpatialCRS;
            IPolyline line = new GeometryFactory().CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;

            line.SpatialCRS = new CRSFactory().CreateFromWKT(wkt) as ISpatialCRS;

            XmlNodeList nodes = xmlDoc.SelectNodes("root/Waypoint");
            int         i     = 0;

            foreach (XmlNode node in nodes)
            {
                double x = double.Parse(node.SelectSingleNode("X").InnerText);
                double y = double.Parse(node.SelectSingleNode("Y").InnerText);
                double z = double.Parse(node.SelectSingleNode("Z").InnerText);
                position.Set(x, y, z);
                point.Position = position;
                if (line.PointCount == 0)
                {
                    line.StartPoint = point;
                }
                else
                {
                    line.AddPointAfter(i - 1, point);
                }
                i++;

                double heading = double.Parse(node.SelectSingleNode("Heading").InnerText);
                double tilt    = double.Parse(node.SelectSingleNode("Tilt").InnerText);
                double roll    = double.Parse(node.SelectSingleNode("Roll").InnerText);
                double when    = double.Parse(node.SelectSingleNode("When").InnerText);
                angle.Set(heading, tilt, roll);
                scale.Set(1, 1, 1);
                motionPath.AddWaypoint2(point, angle, scale, when);
            }

            IRenderPolyline rpl = this.axRenderControl1.ObjectManager.CreateRenderPolyline(line, null, selectedId);

            rpl.Name = "RenderPolyline";
            TreeNode treeNode = new TreeNode("RenderPolyline", 1, 1);

            treeNode.Tag     = rpl.Guid;
            treeNode.Checked = true;
            selectedNode.Nodes.Add(treeNode);
            this.treeView1.UpdateView();
        }
Exemple #5
0
        public VideoObject()
        {
            v3.Set(0, -90, 0);
            Angle = v3.Heading.ToString() + "," + v3.Tilt.ToString() + "," + v3.Roll.ToString();

            AspectRatio = 1.36777;
            CanSeek     = false;
            FarClip     = 200.0;
            FieldOfView = 45.0;

            Icon = (strMediaPath + @"\png\camera.png");

            PlaybackRate       = 1.0;
            PlayLoop           = true;
            PlayStatus         = 1;
            PlayVideoOnStartup = true;
            VideoFileName      = (strMediaPath + @"\video\ambulance.AVI");
            VideoLength        = 0;
            VideoOpacity       = 1.0;
            VideoPosition      = 0;
        }
Exemple #6
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;
                //}
            }
        }
Exemple #7
0
        bool axRenderControl1_RcKeyUp(uint Flags, uint Ch)
        {
            if (curVideoIndex < 0)
            {
                return(false);
            }

            switch (Ch)
            {
                #region  键调整
            case (uint)Keys.Q:
            {
                curVideo = videoList[curVideoIndex];
                cp.X    += factor;
                vector.Set(cp.X, cp.Y, cp.Z);
                positionPoint.Position = vector;
                curVideo.Position      = positionPoint;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);

                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.W:
            {
                curVideo = videoList[curVideoIndex];
                cp.X    -= factor;
                vector.Set(cp.X, cp.Y, cp.Z);
                positionPoint.Position = vector;
                curVideo.Position      = positionPoint;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);

                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.E:
            {
                curVideo = videoList[curVideoIndex];
                cp.Y    += factor;
                vector.Set(cp.X, cp.Y, cp.Z);
                positionPoint.Position = vector;
                curVideo.Position      = positionPoint;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.R:
            {
                curVideo = videoList[curVideoIndex];
                cp.Y    -= factor;
                vector.Set(cp.X, cp.Y, cp.Z);
                positionPoint.Position = vector;
                curVideo.Position      = positionPoint;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.T:
            {
                curVideo = videoList[curVideoIndex];
                cp.Z    += factor;
                vector.Set(cp.X, cp.Y, cp.Z);
                positionPoint.Position = vector;
                curVideo.Position      = positionPoint;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.Y:
            {
                curVideo = videoList[curVideoIndex];
                cp.Z    -= factor;
                vector.Set(cp.X, cp.Y, cp.Z);
                positionPoint.Position = vector;
                curVideo.Position      = positionPoint;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.U:
            {
                curVideo    = videoList[curVideoIndex];
                cp.Heading += factor;
                angle.Set(cp.Heading, cp.Tilt, cp.Roll);
                curVideo.Angle = angle;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.I:
            {
                curVideo    = videoList[curVideoIndex];
                cp.Heading -= factor;
                angle.Set(cp.Heading, cp.Tilt, cp.Roll);
                curVideo.Angle = angle;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.O:
            {
                curVideo = videoList[curVideoIndex];
                cp.Tilt += factor;
                vector.Set(cp.X, cp.Y, cp.Z);
                angle.Set(cp.Heading, cp.Tilt, cp.Roll);
                curVideo.Angle = angle;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.P:
            {
                curVideo = videoList[curVideoIndex];
                cp.Tilt -= factor;
                angle.Set(cp.Heading, cp.Tilt, cp.Roll);
                curVideo.Angle = angle;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.D:
            {
                curVideo = videoList[curVideoIndex];
                cp.Roll += factor;
                angle.Set(cp.Heading, cp.Tilt, cp.Roll);
                curVideo.Angle = angle;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.F:
            {
                curVideo = videoList[curVideoIndex];
                cp.Roll -= factor;
                angle.Set(cp.Heading, cp.Tilt, cp.Roll);
                curVideo.Angle = angle;
                //this.axRenderControl1.Camera.SetCamera(vector, angle, gviSetCameraFlags.gviSetCameraNoFlags);
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.G:
            {
                curVideo             = videoList[curVideoIndex];
                cp.AspectRatio      += factor;
                curVideo.AspectRatio = cp.AspectRatio;
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.H:
            {
                curVideo             = videoList[curVideoIndex];
                cp.AspectRatio      -= factor;
                curVideo.AspectRatio = cp.AspectRatio;
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.J:
            {
                curVideo             = videoList[curVideoIndex];
                cp.FieldOfView      += factor;
                curVideo.FieldOfView = cp.FieldOfView;
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.K:
            {
                curVideo             = videoList[curVideoIndex];
                cp.FieldOfView      -= factor;
                curVideo.FieldOfView = cp.FieldOfView;
                DataRow dr = dt.Rows[curRowIndex];
                dr["Location"] = cp;
            }
            break;

            case (uint)Keys.D1:
            {
                factor = 10;
            }
            break;

            case (uint)Keys.D2:
            {
                factor = 1;
            }
            break;

            case (uint)Keys.D3:
            {
                factor = 0.1;
            }
            break;

            case (uint)Keys.D4:
            {
                factor = 0.01;
            }
            break;

                #endregion
            case (uint)Keys.S:
            {
                String str = cp.PropertyStrings();
                streamWriter.WriteLine(str);
                streamWriter.Flush();
            }
            break;

            case (uint)Keys.C:
            {
                curVideo             = videoList[curVideoIndex];
                curVideo.VisibleMask = gviViewportMask.gviViewAllNormalView;
            }
            break;

            case (uint)Keys.V:
            {
                curVideo             = videoList[curVideoIndex];
                curVideo.VisibleMask = gviViewportMask.gviViewNone;
            }
            break;
            }

            return(true);
        }
Exemple #8
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 + @"\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;
                        }
                        angle.Set(0, -20, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle);
                    }
                    hasfly = true;
                }
            }

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "TerrainRoute.html";
            }
        }
Exemple #9
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";
            }
        }
Exemple #10
0
        public MainForm()
        {
            InitializeComponent();

            // 初始化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 + @"\BIMTIME.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);

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

            // 设置时间轴
            keyDatetimesList.Sort();
            if (keyDatetimesList.Count > 3)
            {
                TimeSpan tsmin = keyDatetimesList[0] - dayLongLongAgo;
                this.trackBarTime.Minimum        = tsmin.Days - 1;
                this.trackBarTimeCompare.Minimum = tsmin.Days - 1;
                TimeSpan tsmax = keyDatetimesList[keyDatetimesList.Count - 2] - dayLongLongAgo;
                this.trackBarTime.Maximum        = tsmax.Days + 1;
                this.trackBarTimeCompare.Maximum = tsmax.Days + 1;
            }

            // CreateFeautureLayer
            bool hasfly = false;

            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);
                    if (featureLayer == null)
                    {
                        continue;
                    }

                    #region 设置时态
                    featureLayer.EnableTemporal = true;
                    layerList.Add(featureLayer);

                    //设置curLayer的时刻
                    this.trackBarTime.Value = this.trackBarTime.Minimum;
                    DateTime d = dayLongLongAgo.AddDays((double)this.trackBarTime.Value);
                    this.labelTime.Text = d.ToString();
                    featureLayer.Time   = d;
                    #endregion

                    #region 比较规则
                    pset.SetProperty("提前", "$(starttime)");
                    featureLayer.CompareRenderRuleVariants = pset;

                    IValueMapGeometryRender render = new ValueMapGeometryRender();
                    {
                        IGeometryRenderScheme scheme = new GeometryRenderScheme();
                        IComparedRenderRule   rule   = new ComparedRenderRule();
                        rule.LookUpField     = "实际开始时间";
                        rule.CompareVariant  = "提前";
                        rule.CompareOperator = gviCompareType.gviCompareLess;
                        scheme.AddRule(rule);
                        IModelPointSymbol symbol = new ModelPointSymbol();
                        symbol.EnableColor = true;
                        symbol.Color       = System.Drawing.Color.Green;
                        scheme.Symbol      = symbol;
                        render.AddScheme(scheme);
                    }
                    {
                        IGeometryRenderScheme scheme = new GeometryRenderScheme();
                        IComparedRenderRule   rule   = new ComparedRenderRule();
                        rule.LookUpField     = "实际开始时间";
                        rule.CompareVariant  = "提前";
                        rule.CompareOperator = gviCompareType.gviCompareGreaterOrEqual;
                        scheme.AddRule(rule);
                        IModelPointSymbol symbol = new ModelPointSymbol();
                        symbol.EnableColor = false;
                        scheme.Symbol      = symbol;
                        render.AddScheme(scheme);
                    }
                    featureLayer.SetGeometryRender(render);
                    #endregion

                    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, -52, 0);
                        position.Set(-13.44, -88.77, 59.28);
                        this.axRenderControl1.Camera.LookAt(position, 100, angle);
                        hasfly = true;
                    }
                }
            }

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "FiveDShow.html";
            }
        }
Exemple #11
0
        private void DrawBox()
        {
            try
            {
                IPolyline line = this._drawTool.GetGeo() as IPolyline;
                if (line == null || line.PointCount != 2)
                {
                    return;
                }
                DF3DApplication app = DF3DApplication.Application;
                if (app == null || app.Current3DMapControl == null)
                {
                    return;
                }


                if (this._renderBox != null)
                {
                    app.Current3DMapControl.ObjectManager.DeleteObject(this._renderBox.Guid);
                    this._renderBox = null;
                }
                if (this._renderPolygon != null)
                {
                    app.Current3DMapControl.ObjectManager.DeleteObject(this._renderPolygon.Guid);
                    this._renderPolygon = null;
                }

                double      middleZ    = (line.StartPoint.Z + line.EndPoint.Z) / 2;
                double      minZ       = middleZ + (double)this.seMinHeight.Value;
                double      maxZ       = middleZ + (double)this.seMaxHeight.Value;
                IPoint      startPoint = line.StartPoint;
                IPoint      endPoint   = line.EndPoint;
                IEulerAngle ang        = app.Current3DMapControl.Camera.GetAimingAngles2(startPoint, endPoint);
                IEulerAngle angcz      = new EulerAngle();
                angcz.Set(ang.Heading - 90, ang.Tilt, ang.Roll);
                IPoint pt1 = app.Current3DMapControl.Camera.GetAimingPoint2(startPoint, angcz, this.tbcClipDis.Value);
                IPoint pt2 = app.Current3DMapControl.Camera.GetAimingPoint2(endPoint, angcz, this.tbcClipDis.Value);

                ICRSFactory      crsFact = new CRSFactory();
                ISpatialCRS      crs     = crsFact.CreateFromWKT(app.Current3DMapControl.GetCurrentCrsWKT()) as ISpatialCRS;
                IGeometryFactory geoFact = new GeometryFactoryClass();
                IPoint           pointb1 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointb1.SpatialCRS = crs;
                pointb1.SetCoords(startPoint.X, startPoint.Y, minZ, 0, 0);
                IPoint pointb2 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointb2.SpatialCRS = crs;
                pointb2.SetCoords(endPoint.X, endPoint.Y, minZ, 0, 0);
                IPoint pointb3 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointb3.SpatialCRS = crs;
                pointb3.SetCoords(pt2.X, pt2.Y, minZ, 0, 0);
                IPoint pointb4 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointb1.SpatialCRS = crs;
                pointb4.SetCoords(pt1.X, pt1.Y, minZ, 0, 0);
                IPolygon polygonBottom = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygonBottom.SpatialCRS = crs;
                polygonBottom.ExteriorRing.AppendPoint(pointb1);
                polygonBottom.ExteriorRing.AppendPoint(pointb2);
                polygonBottom.ExteriorRing.AppendPoint(pointb3);
                polygonBottom.ExteriorRing.AppendPoint(pointb4);

                IPoint pointt1 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointt1.SpatialCRS = crs;
                pointt1.SetCoords(startPoint.X, startPoint.Y, maxZ, 0, 0);
                IPoint pointt2 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointt2.SpatialCRS = crs;
                pointt2.SetCoords(endPoint.X, endPoint.Y, maxZ, 0, 0);
                IPoint pointt3 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointt3.SpatialCRS = crs;
                pointt3.SetCoords(pt2.X, pt2.Y, maxZ, 0, 0);
                IPoint pointt4 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointt4.SpatialCRS = crs;
                pointt4.SetCoords(pt1.X, pt1.Y, maxZ, 0, 0);
                IPolygon polygonTop = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygonTop.SpatialCRS = crs;
                polygonTop.ExteriorRing.AppendPoint(pointt1);
                polygonTop.ExteriorRing.AppendPoint(pointt2);
                polygonTop.ExteriorRing.AppendPoint(pointt3);
                polygonTop.ExteriorRing.AppendPoint(pointt4);

                IPolygon polygon1 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon1.SpatialCRS = crs;
                polygon1.ExteriorRing.AppendPoint(pointb1);
                polygon1.ExteriorRing.AppendPoint(pointb2);
                polygon1.ExteriorRing.AppendPoint(pointt2);
                polygon1.ExteriorRing.AppendPoint(pointt1);

                IPolygon polygon2 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon2.SpatialCRS = crs;
                polygon2.ExteriorRing.AppendPoint(pointb1);
                polygon2.ExteriorRing.AppendPoint(pointb4);
                polygon2.ExteriorRing.AppendPoint(pointt4);
                polygon2.ExteriorRing.AppendPoint(pointt1);

                IPolygon polygon3 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon3.SpatialCRS = crs;
                polygon3.ExteriorRing.AppendPoint(pointb2);
                polygon3.ExteriorRing.AppendPoint(pointb3);
                polygon3.ExteriorRing.AppendPoint(pointt3);
                polygon3.ExteriorRing.AppendPoint(pointt2);

                IPolygon polygon4 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon4.SpatialCRS = crs;
                polygon4.ExteriorRing.AppendPoint(pointb3);
                polygon4.ExteriorRing.AppendPoint(pointb4);
                polygon4.ExteriorRing.AppendPoint(pointt4);
                polygon4.ExteriorRing.AppendPoint(pointt3);

                IMultiPolygon multiPolygon = geoFact.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon;
                multiPolygon.SpatialCRS = crs;
                multiPolygon.AddPolygon(polygonBottom);
                multiPolygon.AddPolygon(polygonTop);
                //multiPolygon.AddPolygon(polygon1);
                multiPolygon.AddPolygon(polygon2);
                multiPolygon.AddPolygon(polygon3);
                multiPolygon.AddPolygon(polygon4);

                ISurfaceSymbol ss = new SurfaceSymbolClass();
                ss.Color = 0x550000AA;
                ICurveSymbol cs = new CurveSymbolClass();
                cs.Color            = 0xff0000AA;
                ss.BoundarySymbol   = cs;
                this._renderPolygon = app.Current3DMapControl.ObjectManager.CreateRenderPolygon(polygon1, ss, app.Current3DMapControl.ProjectTree.RootID);

                ISurfaceSymbol ss1 = new SurfaceSymbolClass();
                ss1.Color = 0x88FFFFFF;
                ICurveSymbol cs1 = new CurveSymbolClass();
                cs1.Color          = 0xffffffff;
                ss1.BoundarySymbol = cs1;
                this._renderBox    = app.Current3DMapControl.ObjectManager.CreateRenderMultiPolygon(multiPolygon, ss1, app.Current3DMapControl.ProjectTree.RootID);

                _env    = null;
                _ang    = null;
                _center = null;

                _env = new EnvelopeClass();
                double xdis = Math.Sqrt((pointb1.X - pointb2.X) * (pointb1.X - pointb2.X) + (pointb1.Y - pointb2.Y) * (pointb1.Y - pointb2.Y)) / 2;
                double ydis = Math.Sqrt((pointb1.X - pointb4.X) * (pointb1.X - pointb4.X) + (pointb1.Y - pointb4.Y) * (pointb1.Y - pointb4.Y)) / 2;
                _env.MinZ = -ydis;
                _env.MaxZ = ydis;
                _env.MinX = -xdis;
                _env.MaxX = xdis;
                _env.MinY = -(maxZ - minZ) / 2.0;
                _env.MaxY = (maxZ - minZ) / 2.0;

                _center            = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                _center.SpatialCRS = crs;
                _center.X          = polygonBottom.Centroid.X;
                _center.Y          = polygonBottom.Centroid.Y;
                _center.Z          = polygon1.Centroid.Z;

                _ang = new EulerAngleClass();
                _ang.Set(angcz.Heading, 0, 0);
            }
            catch (Exception ex)
            {
            }
        }
Exemple #12
0
        private void AxRenderControl1_RcUIWindowEvent(IUIEventArgs EventArgs, gviUIEventType EventType)
        {
            IUIMouseEventArgs args = EventArgs as IUIMouseEventArgs;

            if (args.UIEventWindow == null)
            {
                return;
            }

            if (EventType == gviUIEventType.gviUIMouseClick)
            {
                gviUIWindowType winType = args.UIEventWindow.Type;
                if (winType == gviUIWindowType.gviUIImageButton)
                {
                    switch (args.UIEventWindow.Name)
                    {
                    case "漫游":
                        this.axRenderControl1.InteractMode = gviInteractMode.gviInteractNormal;
                        break;

                    case "点选":
                        this.axRenderControl1.InteractMode = gviInteractMode.gviInteractSelect;
                        break;

                    case "location1":
                        vec.Set(15415.510188040265, 35593.117437895737, 59.003287982044796);
                        ang.Set(47.7, -30.55, 0);
                        this.axRenderControl1.Camera.SetCamera(vec, ang, gviSetCameraFlags.gviSetCameraNoFlags);
                        break;

                    case "location2":
                        vec.Set(15243.39327614102, 35593.454101290568, 19.083291340718386);
                        ang.Set(-37.01, -15.27, 0);
                        this.axRenderControl1.Camera.SetCamera(vec, ang, gviSetCameraFlags.gviSetCameraNoFlags);
                        break;

                    case "location3":
                        vec.Set(15150.53692901546, 35785.206458874149, 21.492597977763278);
                        ang.Set(-136.66, -19.68, 0);
                        this.axRenderControl1.Camera.SetCamera(vec, ang, gviSetCameraFlags.gviSetCameraNoFlags);
                        break;

                    case "location4":
                        vec.Set(15562.369345366114, 36027.787538479148, 9.5395100144668721);
                        ang.Set(-98.11, -5.3, 0);
                        this.axRenderControl1.Camera.SetCamera(vec, ang, gviSetCameraFlags.gviSetCameraNoFlags);
                        break;

                    case "location5":
                        vec.Set(15290.261360847539, 35689.443985629681, 25.558723498791508);
                        ang.Set(-34.53, -34.98, 0);
                        this.axRenderControl1.Camera.SetCamera(vec, ang, gviSetCameraFlags.gviSetCameraNoFlags);
                        break;

                    case "SunShine":
                        this.axRenderControl1.ObjectManager.GetSkyBox(0).Weather = gviWeatherType.gviWeatherSunShine;
                        imgbtn1.IsVisible = false;
                        imgbtn2.IsVisible = false;
                        imgbtn3.IsVisible = false;
                        break;

                    case "HeavyRain":
                        this.axRenderControl1.ObjectManager.GetSkyBox(0).Weather = gviWeatherType.gviWeatherHeavyRain;
                        imgbtn1.IsVisible = false;
                        imgbtn2.IsVisible = false;
                        imgbtn3.IsVisible = false;
                        break;

                    case "HeavySnow":
                        this.axRenderControl1.ObjectManager.GetSkyBox(0).Weather = gviWeatherType.gviWeatherHeavySnow;
                        imgbtn1.IsVisible = false;
                        imgbtn2.IsVisible = false;
                        imgbtn3.IsVisible = false;
                        break;
                    }
                }
                else if (winType == gviUIWindowType.gviUITextButton)
                {
                    switch (args.UIEventWindow.Name)
                    {
                    case "SunShine":
                        this.axRenderControl1.ObjectManager.GetSkyBox(0).Weather = gviWeatherType.gviWeatherSunShine;
                        imgbtn1.IsVisible = false;
                        imgbtn2.IsVisible = false;
                        imgbtn3.IsVisible = false;
                        break;

                    case "HeavyRain":
                        this.axRenderControl1.ObjectManager.GetSkyBox(0).Weather = gviWeatherType.gviWeatherHeavyRain;
                        imgbtn1.IsVisible = false;
                        imgbtn2.IsVisible = false;
                        imgbtn3.IsVisible = false;
                        break;

                    case "HeavySnow":
                        this.axRenderControl1.ObjectManager.GetSkyBox(0).Weather = gviWeatherType.gviWeatherHeavySnow;
                        imgbtn1.IsVisible = false;
                        imgbtn2.IsVisible = false;
                        imgbtn3.IsVisible = false;
                        break;
                    }
                }
            }
            else if (EventType == gviUIEventType.gviUIMouseEntersArea)
            {
                gviUIWindowType winType = args.UIEventWindow.Type;
                if (winType == gviUIWindowType.gviUIImageButton)
                {
                    switch (args.UIEventWindow.Name)
                    {
                    case "天气":
                        imgbtn1.IsVisible = true;
                        imgbtn2.IsVisible = true;
                        imgbtn3.IsVisible = true;
                        break;
                    }
                }
            }
            //else if (EventType == gviUIEventType.gviUIMouseLeavesArea)
            //{
            //    gviUIWindowType winType = args.UIEventWindow.Type;
            //    if (winType == gviUIWindowType.gviUIImageButton)
            //    {
            //        switch (args.UIEventWindow.Name)
            //        {
            //            case "天气":
            //                imgbtn1.IsVisible = false;
            //                imgbtn2.IsVisible = false;
            //                imgbtn3.IsVisible = false;
            //                break;
            //        }
            //    }
            //}
        }
Exemple #13
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);
            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 + @"\TemporalOldSummerPalace.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);

                bool hasSetTime = false;
                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.Name.Equals("水系"))
                    {
                        ///* 准备数据时打开,执行完后注释掉
                        // 开启时态
                        //if (!fc.HasTemporal())
                        //{
                        //    fc.LockType = gviLockType.gviLockExclusiveSchema;
                        //    DateTime defaultBirthDatetime = new DateTime(2010, 1, 1);
                        //    fc.EnableTemporal(defaultBirthDatetime, "StartDate", "EndDate");
                        //    fc.LockType = gviLockType.gviLockSharedSchema;
                        //}

                        if (!hasSetTime)
                        {
                            ITemporalManager tm    = fc.TemporalManager;
                            DateTime[]       times = tm.GetKeyDatetimes();
                            for (int tt = 0; tt < times.Length; tt++)
                            {
                                double keytime = times[tt].ToOADate();
                                timelist.Add(keytime);
                            }

                            if (timelist.Count > 3)
                            {
                                this.trackBarTime.Minimum = (int)((double)timelist[0]);
                                this.trackBarTime.Maximum = (int)((double)timelist[timelist.Count - 1] - 1);
                            }
                            // 设置时间轴
                            this.trackBarTime.Value = this.trackBarTime.Minimum;

                            // 创建OverlayLabel
                            label      = this.axRenderControl1.ObjectManager.CreateOverlayLabel(rootId);
                            label.Text = "乾隆初期";
                            label.SetX(0, 0.5f, 0);
                            label.SetY(0, 0, 0.5f);
                            label.SetWidth(0, 1, 0);
                            label.SetHeight(0, 0, 1);
                            label.Alignment = gviPivotAlignment.gviPivotAlignTopLeft;
                            TextAttribute att = new TextAttribute();
                            att.Font        = "幼圆";
                            att.TextColor   = System.Drawing.Color.Red;
                            att.TextSize    = 25;
                            label.TextStyle = att;

                            hasSetTime = true;
                        }
                    }
                } //end of fc
            }
            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)
                {
                    IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer(
                        fc, geoName, null, null, rootId);

                    if (!fc.Name.Equals("水系") && geoName.Equals("Geometry"))
                    {
                        featureLayer.EnableTemporal = true;
                        layers.Add(featureLayer);

                        //设置curLayer的时刻
                        if (featureLayer != null)
                        {
                            DateTime d = DateTime.FromOADate((double)this.trackBarTime.Value);
                            featureLayer.Time = d;
                        }
                    }

                    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, -40, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 100, angle);
                    }
                    hasfly = true;
                }
            }

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "TemporalOldSummerPalace.html";
            }
        }
Exemple #14
0
        public MainForm()
        {
            InitializeComponent();

            // 初始化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;

            // 设置天空盒
            flag = Application.StartupPath.LastIndexOf("Samples");
            if (flag > -1)
            {
                string  tmpSkyboxPath = Path.Combine(Application.StartupPath.Substring(0, flag), @"Samples\Media\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 = Path.Combine(Application.StartupPath.Substring(0, flag), @"Samples\Media\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;
            }

            // 设置时间轴
            this.trackBarTime.Minimum = 0;
            this.trackBarTime.Maximum = 4;

            // CreateFeautureLayer
            bool hasfly = false;

            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);
                    if (featureLayer == null)
                    {
                        continue;
                    }

                    if (fc.Name.Equals("Building") && geoName.Equals("Geometry"))
                    {
                        pset = new PropertySet();
                        pset.SetProperty("type", this.trackBarTime.Minimum);
                        featureLayer.CompareRenderRuleVariants = pset;

                        IValueMapGeometryRender render = new ValueMapGeometryRender();
                        {
                            IGeometryRenderScheme scheme = new GeometryRenderScheme();
                            IComparedRenderRule   rule   = new ComparedRenderRule();
                            rule.LookUpField     = "BuildType";
                            rule.CompareVariant  = "type";
                            rule.CompareOperator = gviCompareType.gviCompareEqual;
                            scheme.AddRule(rule);
                            IModelPointSymbol symbol = new ModelPointSymbol();
                            symbol.EnableColor = true;
                            symbol.Color       = System.Drawing.Color.Green;
                            scheme.Symbol      = symbol;
                            render.AddScheme(scheme);
                        }
                        {
                            IGeometryRenderScheme scheme = new GeometryRenderScheme();
                            IComparedRenderRule   rule   = new ComparedRenderRule();
                            rule.LookUpField     = "BuildType";
                            rule.CompareVariant  = "type";
                            rule.CompareOperator = gviCompareType.gviCompareLessOrEqual;
                            scheme.AddRule(rule);
                            render.AddScheme(scheme);
                        }
                        featureLayer.SetGeometryRender(render);
                        buildlayer = 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;
                        }
                        angle.Set(0, -30, 0);
                        this.axRenderControl1.Camera.LookAt(env.Center, 300, angle);
                        hasfly = true;
                    }
                }
            }

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