Beispiel #1
0
        /// <summary>
        /// 预览按钮处理。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Preview(object sender, RoutedEventArgs e)
        {
            try
            {
                // 生成边坡实体集合,按实体边界获取截取窗口。
                previewEnts = MakeBianpo(view);
                var extents = new AcDb.Extents3d();
                foreach (var ent in previewEnts.OfType <AcDb.Curve>())
                {
                    extents.AddExtents(ent.GeometricExtents);
                }
                previewExtents = extents;

                // 生成Bitmap,显示到界面的图片上。
                using (var bitmap = GraphicHelper.Snapshort(previewEnts,
                                                            kPreviewImageWidth, kPreviewImageHeight,
                                                            previewExtents.MinPoint, previewExtents.MaxPoint))
                {
                    ShowImage(bitmap);
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }
Beispiel #2
0
        private void PreviewImage_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            try
            {
                if (previewEnts == null)
                {
                    return;
                }

                // 在鼠标位置放大一倍。
                if (!isPreviewImageZooming && e.Delta > 0)
                {
                    isPreviewImageZooming = true;

                    // 将原预览实体范围扩展为与图片比例相同,以准确定位扩大点。
                    var minPoint     = previewExtents.MinPoint;
                    var maxPoint     = previewExtents.MaxPoint;
                    var origWidth    = maxPoint.X - minPoint.X;
                    var origHeight   = maxPoint.Y - minPoint.Y;
                    var origRatio    = origHeight > 0 ? (origWidth / origHeight) : 1;
                    var prevImgRatio = kPreviewImageWidth / kPreviewImageHeight;
                    if (origRatio > prevImgRatio) // 过宽。
                    {
                        var heightDiff = origWidth / prevImgRatio - origHeight;
                        minPoint = new Point3d(minPoint.X, minPoint.Y - heightDiff * 0.5, 0);
                        maxPoint = new Point3d(maxPoint.X, maxPoint.Y + heightDiff * 0.5, 0);
                    }
                    else if (origRatio < prevImgRatio) // 过高。
                    {
                        var widthDiff = origHeight * prevImgRatio - origWidth;
                        minPoint = new Point3d(minPoint.X - widthDiff * 0.5, minPoint.Y, 0);
                        maxPoint = new Point3d(maxPoint.X + widthDiff * 0.5, maxPoint.Y, 0);
                    }

                    // 获取缩放后的截取窗口。
                    var zoomPtOnImg = e.GetPosition(PreviewImage);
                    zoomPtOnImg = new System.Windows.Point(
                        zoomPtOnImg.X * kPreviewImageWidth / PreviewImage.ActualWidth,
                        zoomPtOnImg.Y * kPreviewImageHeight / PreviewImage.ActualHeight);
                    var zoomVec = maxPoint - minPoint;
                    var zoomPt  = new Point3d(
                        minPoint.X + zoomVec.X * zoomPtOnImg.X / kPreviewImageWidth,
                        maxPoint.Y - zoomVec.X * zoomPtOnImg.Y / kPreviewImageHeight,
                        0);

                    // 生成Bitmap,显示到界面的图片上。
                    using (var bitmap = GraphicHelper.Snapshort(previewEnts,
                                                                kPreviewImageWidth, kPreviewImageHeight,
                                                                zoomPt - zoomVec * 0.25, zoomPt + zoomVec * 0.25))
                    {
                        ShowImage(bitmap);
                    }
                }

                // 还原。
                if (isPreviewImageZooming && e.Delta < 0)
                {
                    isPreviewImageZooming = false;

                    // 生成Bitmap,显示到界面的图片上。
                    using (var bitmap = GraphicHelper.Snapshort(previewEnts,
                                                                kPreviewImageWidth, kPreviewImageHeight,
                                                                previewExtents.MinPoint, previewExtents.MaxPoint))
                    {
                        ShowImage(bitmap);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }