예제 #1
0
        public void AddItem(Drawable item)
        {
            if (IsDesigner)
            {
                return;
            }

            Init();
            Extents3d?itemExtents = item.Bounds;

            if (itemExtents.HasValue)
            {
                if (items.Count == 0)
                {
                    extents.Set(itemExtents.Value.MinPoint, itemExtents.Value.MaxPoint);
                }
                else
                {
                    extents.AddExtents(itemExtents.Value);
                }
            }
            items.Add(item);

            Refresh();
        }
예제 #2
0
        /// <summary>
        ///     Method to zoom a viewport to the extents of an input entity
        /// </summary>
        /// <param name="acCurDb"></param>
        /// <param name="acCurVp"></param>
        /// <param name="acEnt"></param>
        private void ZoomViewport(Database acCurDb, Viewport acCurVp, Extents3d ext)
        {
            // get the screen aspect ratio to calculate
            // the height and width
            // width/height
            var mScrRatio = acCurVp.Width / acCurVp.Height;
            var mMaxExt   = acCurDb.Extmax;
            var mMinExt   = acCurDb.Extmin;

            if (ext != null)
            {
                mMaxExt = ext.MaxPoint;
                mMinExt = ext.MinPoint;
            }

            var mExtents = new Extents3d();

            mExtents.Set(mMinExt, mMaxExt);

            // prepare Matrix for DCS to WCS transformation
            var matWcs2Dcs = Matrix3d.PlaneToWorld(acCurVp.ViewDirection);

            matWcs2Dcs = Matrix3d.Displacement(acCurVp.ViewTarget - Point3d.Origin) * matWcs2Dcs;
            matWcs2Dcs = Matrix3d.Rotation(-acCurVp.TwistAngle, acCurVp.ViewDirection, acCurVp.ViewTarget) * matWcs2Dcs;
            matWcs2Dcs = matWcs2Dcs.Inverse();

            // tranform the extents to the DCS
            // defined by the viewdir
            mExtents.TransformBy(matWcs2Dcs);

            // width of the extents in current view
            var mWidth = mExtents.MaxPoint.X - mExtents.MinPoint.X;

            // height of the extents in current view
            var mHeight = mExtents.MaxPoint.Y - mExtents.MinPoint.Y;

            // get the view center point
            var mCentPt = new Point2d(
                (mExtents.MaxPoint.X + mExtents.MinPoint.X) * 0.5,
                (mExtents.MaxPoint.Y + mExtents.MinPoint.Y) * 0.5);

            // check if the width 'fits' in current window,
            // if not then get the new height as
            // per the viewports aspect ratio
            if (mWidth > mHeight * mScrRatio)
            {
                mHeight = mWidth / mScrRatio;
            }

            // set the view height - adjusted by view Identifier
            acCurVp.ViewHeight = mHeight * 1.25;

            // set the view center
            acCurVp.ViewCenter = mCentPt;
        }
        private void readSurferGridData(string path)
        {
            // 读数据
            double yfirst = 0;  //记录第一个读出来的y坐标,如果发生变化,说明第一行数据读取完毕

            List <double> databuf = new List <double>();
            StreamReader  sr      = new StreamReader(path);
            int           index   = 0;

            while (!sr.EndOfStream)
            {
                string strRead = sr.ReadLine();
                if (strRead != "")
                {
                    string[] strs = strRead.Split(' ');
                    databuf.Add(double.Parse(strs[2]));
                    // 记录图幅范围,并统计行数
                    if (index == 0)
                    {
                        yfirst = double.Parse(strs[1]);
                        Point3d pt = new Point3d(double.Parse(strs[0]), double.Parse(strs[1]), 0);
                        m_extents.Set(pt, pt);
                    }
                    if (sr.EndOfStream)
                    {
                        m_extents.AddPoint(new Point3d(double.Parse(strs[0]), double.Parse(strs[1]), 0));
                    }
                    // y值发生变化,记录下列数
                    if (double.Parse(strs[1]) != yfirst && m_XSize == 0)
                    {
                        m_XSize = index;
                    }
                }
                index++;
            }
            m_YSize      = databuf.Count / m_XSize;
            m_elevations = databuf.ToArray();
            sr.Close();
        }