Example #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (!suspended && init && !disposed && !Disposing && !IsDesigner)
            {
                device.BackgroundColor = BackColor;
                device.OnSize(ClientSize);
                view.EraseAll();
                Point3d pt1 = extents.MinPoint;
                Point3d pt2 = extents.MaxPoint;
                Point3d ptm = new Point3d((pt1.X + pt2.X) / 2.0, (pt1.Y + pt2.Y) / 2.0, 0.0);
                Point3d ptc = new Point3d(ptm.X, ptm.Y, 1.0);
                double  fw  = Math.Abs(pt2.X - pt1.X);
                double  fh  = Math.Abs(pt2.Y - pt1.Y);
                view.SetView(ptc, ptm, Vector3d.YAxis, fw, fh);
                foreach (Drawable item in items)
                {
                    view.Add(item, model);
                }
                view.Update();
                using (Bitmap bmp = view.GetSnapshot(ClientRectangle))
                {
                    e.Graphics.DrawImageUnscaled(bmp, 0, 0);
                }

                if (m_Selected)
                {
                    using (Pen pen = new Pen(m_SelectionColor, 2.0f))
                    {
                        Rectangle rec = ClientRectangle;
                        rec.Inflate(-2, -2);
                        e.Graphics.DrawRectangle(pen, rec);
                    }
                }
            }
        }
Example #2
0
        public static void SetViewTo(Autodesk.AutoCAD.GraphicsSystem.View view, Database db)
        {
            if (_extMax.Equals(Point3d.Origin) && _extMin.Equals(Point3d.Origin))
            {
                // just check we have valid extents
                if (db.Extmax.X < db.Extmin.X || db.Extmax.Y < db.Extmin.Y || db.Extmax.Z < db.Extmax.Z)
                {
                    db.Extmin = new Point3d(0, 0, 0);
                    db.Extmax = new Point3d(400, 400, 400);
                }
                // get the dwg extents
                _extMax = db.Extmax;
                _extMin = db.Extmin;
            }

            // now the active viewport info
            double   height = 0.0, width = 0.0, viewTwist = 0.0;
            Point3d  targetView = new Point3d();
            Vector3d viewDir    = new Vector3d();

            GetActiveViewPortInfo(ref height, ref width, ref targetView, ref viewDir, ref viewTwist, true);
            // from the data returned let's work out the viewmatrix
            viewDir = viewDir.GetNormal();

            Vector3d viewXDir = viewDir.GetPerpendicularVector().GetNormal();

            viewXDir = viewXDir.RotateBy(viewTwist, -viewDir);
            Vector3d viewYDir  = viewDir.CrossProduct(viewXDir);
            Point3d  boxCenter = _extMin + 0.5 * (_extMax - _extMin);
            Matrix3d viewMat;

            viewMat = Matrix3d.AlignCoordinateSystem(boxCenter, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
                                                     boxCenter, viewXDir, viewYDir, viewDir).Inverse();
            Extents3d wcsExtents  = new Extents3d(_extMin, _extMax);
            Extents3d viewExtents = wcsExtents;

            viewExtents.TransformBy(viewMat);
            double  xMax = System.Math.Abs(viewExtents.MaxPoint.X - viewExtents.MinPoint.X);
            double  yMax = System.Math.Abs(viewExtents.MaxPoint.Y - viewExtents.MinPoint.Y);
            Point3d eye  = boxCenter + viewDir;

            view.SetView(eye, boxCenter, viewYDir, xMax, yMax);

            view.Invalidate();
            view.Update();
        }