コード例 #1
0
        public static Bitmap CreateAutoSizedBitmap(
            DxfModel model,
            GDIGraphics3D cadGraphics,
            SmoothingMode smoothingMode,
            Matrix4D transform,
            System.Drawing.Color backColor,
            Size maxSize)
        {
            cadGraphics.CreateDrawables(model);
            Bounds3D bounds = new Bounds3D();

            cadGraphics.BoundingBox(bounds, transform);
            int      num1       = maxSize.Width - 4;
            int      num2       = maxSize.Height - 4;
            Matrix4D transform1 = DxfUtil.GetScaleTransform(bounds.Corner1, bounds.Corner2, new WW.Math.Point3D(bounds.Corner1.X, bounds.Corner2.Y, 0.0), new WW.Math.Point3D(0.0, (double)num2, 0.0), new WW.Math.Point3D((double)num1, 0.0, 0.0), new WW.Math.Point3D(2.0, 2.0, 0.0)) * transform;

            bounds.Reset();
            cadGraphics.BoundingBox(bounds, transform1);
            if (!bounds.Initialized)
            {
                return(ImageExporter.CreateEmptyBitmap(backColor, maxSize.Width, maxSize.Height));
            }
            WW.Math.Vector3D delta = bounds.Delta;
            int width  = System.Math.Min(maxSize.Width, (int)System.Math.Ceiling(delta.X) + 4);
            int height = System.Math.Min(maxSize.Height, (int)System.Math.Ceiling(delta.Y) + 4);

            return(ImageExporter.CreateBitmap(cadGraphics, smoothingMode, transform1, backColor, width, height));
        }
コード例 #2
0
        public ViewControl()
        {
            InitializeComponent();
            //控制控件闪烁
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); //禁止擦除背景
            SetStyle(ControlStyles.DoubleBuffer, true);         //双缓冲
            SetStyle(ControlStyles.UserPaint, true);            //自行绘制图片
            GraphicsConfig graphicsConfig = new GraphicsConfig();

            graphicsConfig.BackColor = BackColor;
            graphicsConfig.CorrectColorForBackgroundColor = true;
            gdiGraphics3D = new GDIGraphics3D(graphicsConfig);
            gdiGraphics3D.EnableDrawablesUpdate();
            graphicsCache        = new WireframeGraphicsCache(false, true);
            graphicsCache.Config = graphicsConfig;
            graphicsHelper       = new GraphicsHelper(System.Drawing.Color.Blue);
            bounds = new Bounds3D();

            transformationProvider = new SimpleTransformationProvider3D();
            transformationProvider.TransformsChanged += new EventHandler(transformationProvider_TransformsChanged);
            panInteractor              = new SimplePanInteractor(transformationProvider);
            rectZoomInteractor         = new SimpleRectZoomInteractor(transformationProvider);
            zoomWheelInteractor        = new SimpleZoomWheelInteractor(transformationProvider);
            rectZoomInteractorDrawable = new SimpleRectZoomInteractor.WinFormsDrawable(rectZoomInteractor);
        }
コード例 #3
0
 public static Bitmap CreateAutoSizedBitmap(
     GDIGraphics3D cadGraphics,
     SmoothingMode smoothingMode,
     Matrix4D transform)
 {
     return(ImageExporter.CreateAutoSizedBitmap(cadGraphics, smoothingMode, transform, (System.Drawing.Color)cadGraphics.Config.BackColor));
 }
コード例 #4
0
        public static Bitmap CreateBitmap(
            DxfModel model,
            DxfLayout layout,
            ICollection <DxfViewport> viewports,
            GraphicsConfig graphicsConfig,
            SmoothingMode smoothingMode,
            System.Drawing.Color backColor,
            Matrix4D to2DTransform,
            int width,
            int height)
        {
            Bitmap bitmap = new Bitmap(width, height);

            using (Graphics graphics = Graphics.FromImage((Image)bitmap))
            {
                graphics.SmoothingMode = smoothingMode;
                graphics.Clear(backColor);
                if (layout.PaperSpace)
                {
                    GraphicsConfig config = (GraphicsConfig)graphicsConfig.Clone();
                    double         length = to2DTransform.Transform(WW.Math.Vector3D.XAxis).GetLength();
                    config.DotsPerInch = length * layout.GetLineWeightUnitsToPaperUnits() * 2540.0;
                    GDIGraphics3D gdiGraphics3D = new GDIGraphics3D(config);
                    gdiGraphics3D.CreateDrawables(model, layout, viewports);
                    gdiGraphics3D.Draw(graphics, new Rectangle(0, 0, width, height), to2DTransform);
                }
                else
                {
                    GDIGraphics3D gdiGraphics3D = new GDIGraphics3D(graphicsConfig);
                    gdiGraphics3D.CreateDrawables(model);
                    gdiGraphics3D.Draw(graphics, new Rectangle(0, 0, width, height), to2DTransform);
                }
            }
            return(bitmap);
        }
コード例 #5
0
        public static Bitmap CreateViewportConfigurationBitmap(
            DxfModel model,
            string vportName,
            GraphicsConfig graphicsConfig,
            SmoothingMode smoothingMode,
            int width,
            int height)
        {
            Bitmap      bitmap          = new Bitmap(width, height);
            Rectangle2D targetRectangle = new Rectangle2D(0.0, 0.0, (double)width, (double)height);
            Rectangle   drawingBounds   = new Rectangle(0, 0, width, height);

            using (Graphics graphics = Graphics.FromImage((Image)bitmap))
            {
                graphics.SmoothingMode = smoothingMode;
                graphics.Clear((System.Drawing.Color)graphicsConfig.BackColor);
                GDIGraphics3D gdiGraphics3D = new GDIGraphics3D(graphicsConfig);
                gdiGraphics3D.CreateDrawables(model);
                foreach (DxfVPort vport in (DxfHandledObjectCollection <DxfVPort>)model.VPorts)
                {
                    if (vportName.Equals(vport.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        IViewDescription viewDescription = vport.ViewDescription;
                        Matrix4D         transform       = ViewUtil.GetTransform(viewDescription, targetRectangle, true);
                        float            num             = 1f - (float)(viewDescription.ViewportCenter.Y + viewDescription.ViewportHeight / 2.0);
                        RectangleF       rect            = new RectangleF((float)width * (float)(viewDescription.ViewportCenter.X - viewDescription.ViewportWidth / 2.0), (float)height * num, (float)width * (float)viewDescription.ViewportWidth, (float)height * (float)viewDescription.ViewportHeight);
                        graphics.Clip = new System.Drawing.Region(rect);
                        gdiGraphics3D.Draw(graphics, drawingBounds, transform);
                    }
                }
            }
            return(bitmap);
        }
コード例 #6
0
 public ViewControl() {
     InitializeComponent();
     SetStyle(ControlStyles.AllPaintingInWmPaint, true);
     SetStyle(ControlStyles.DoubleBuffer, true);
     SetStyle(ControlStyles.UserPaint, true);
     {
         GraphicsConfig graphicsConfig = new GraphicsConfig(BackColor);
         fishNetGraphics3D = new GDIGraphics3D(graphicsConfig);
     }
     {
         GraphicsConfig graphicsConfig = new GraphicsConfig(BackColor);
         graphicsConfig.FixedForegroundColor = System.Drawing.Color.Red;
         dynamicGdiGraphics3D = new GDIGraphics3D(graphicsConfig);
     }
     {
         GraphicsConfig graphicsConfig = new GraphicsConfig(BackColor);
         axisGraphics3D = new GDIGraphics3D(graphicsConfig);
     }
     {
         GraphicsConfig graphicsConfig = new GraphicsConfig(BackColor);
         polyGdiGraphics3D = new GDIGraphics3D(graphicsConfig);
     }
     this.KeyUp += new KeyEventHandler(ViewControl_KeyUp);
     modelPoly = new DxfModel();
     bounds = new Bounds3D();
 }
コード例 #7
0
ファイル: DxfLwPolylineCreator.cs プロジェクト: 15831944/WW
 public WinFormsDrawable(DxfLwPolylineCreator interactor, GDIGraphics3D graphics)
 {
     this.dxfLwPolylineCreator_0 = interactor;
     this.gdigraphics3D_0        = graphics;
     interactor.Deactivated     += new EventHandler(this.method_1);
     interactor.Changed         += new EventHandler(this.method_0);
 }
コード例 #8
0
 public static Bitmap CreateBitmap(
     GDIGraphics3D cadGraphics,
     Matrix4D transform,
     Size size)
 {
     return(ImageExporter.CreateBitmap(cadGraphics, transform, size.Width, size.Height));
 }
コード例 #9
0
 public static Bitmap CreateAutoSizedBitmap(
     GDIGraphics3D cadGraphics,
     Matrix4D transform,
     System.Drawing.Color backColor)
 {
     return(ImageExporter.CreateAutoSizedBitmap(cadGraphics, SmoothingMode.AntiAlias, transform, backColor));
 }
コード例 #10
0
 public static Bitmap CreateBitmap(
     GDIGraphics3D cadGraphics,
     Matrix4D transform,
     System.Drawing.Color backColor,
     Size size)
 {
     return(ImageExporter.CreateBitmap(cadGraphics, transform, backColor, size.Width, size.Height));
 }
コード例 #11
0
 public static Bitmap CreateBitmap(
     GDIGraphics3D cadGraphics,
     Matrix4D transform,
     int width,
     int height)
 {
     return(ImageExporter.CreateBitmap(cadGraphics, SmoothingMode.AntiAlias, transform, width, height));
 }
コード例 #12
0
 public static Bitmap CreateAutoSizedBitmap(
     DxfModel model,
     GDIGraphics3D cadGraphics,
     Matrix4D transform,
     Size maxSize)
 {
     return(ImageExporter.CreateAutoSizedBitmap(model, cadGraphics, SmoothingMode.AntiAlias, transform, (System.Drawing.Color)cadGraphics.Config.BackColor, maxSize));
 }
コード例 #13
0
        //Get Jpeg from selected Layers
        public Stream GetPictures(Stream input)
        {
            string body = new StreamReader(input).ReadToEnd();
            NameValueCollection _nvc    = HttpUtility.ParseQueryString(body);
            string   _boothOutlineLayer = _nvc["BoothOutline"];
            string   _boothNumberLayer  = _nvc["BoothNumber"];
            string   _fileName          = _nvc["FileName"];
            string   _client_id         = _nvc["ClientId"];
            string   _show_id           = _nvc["ShowId"];
            string   _accessKey         = @_nvc["AccessKey"];
            string   _secretKey         = @_nvc["SecretKey"];
            string   _bucketName        = @_nvc["BucketName"];
            DxfModel _model             = ReadDxf("h://dxf_uploads//" + _client_id + " // " + _show_id + "//" + _fileName);

            foreach (DxfLayer _layer in _model.Layers)
            {
                if (_layer.Name != _boothOutlineLayer && _layer.Name != _boothNumberLayer)
                {
                    _layer.Enabled = false;
                }
            }
            string outfile = Path.GetFileNameWithoutExtension(Path.GetFullPath(_fileName));
            Stream stream;

            GDIGraphics3D graphics = new GDIGraphics3D(GraphicsConfig.BlackBackgroundCorrectForBackColor);
            Size          maxSize  = new Size(750, 750);
            Bitmap        bitmap   =
                ImageExporter.CreateAutoSizedBitmap(
                    _model,
                    graphics,
                    Matrix4D.Identity,
                    System.Drawing.Color.Black,
                    maxSize
                    );
            string fileNameS3 = outfile + ".jpg";
            string filePath   = "h://dxf_uploads//" + _client_id + " // " + _show_id + "//" + fileNameS3;

            stream = File.Create(filePath);
            ImageExporter.EncodeImageToJpeg(bitmap, stream);

            string                      _subDirectory    = _client_id + @"/" + _show_id + @"/dxf";
            AmazonS3Transfer            amazonS3Transfer = new AmazonS3Transfer();
            bool                        uploadStatus     = amazonS3Transfer.sendMyFileToS3(stream, _bucketName, _subDirectory, fileNameS3, _accessKey, _secretKey);
            Dictionary <string, string> status           = new Dictionary <string, string>();

            if (uploadStatus == true)
            {
                status.Add("status_code", "1");
            }
            else
            {
                status.Add("status_code", "0");
            }
            string result = JsonConvert.SerializeObject(status);

            WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            return(new MemoryStream(Encoding.UTF8.GetBytes(result)));
        }
コード例 #14
0
ファイル: CADHelper.cs プロジェクト: kamchung322/Namwah
        public static void ExportToJpg(DxfModel model, string fileName, Size maxSize)
        {
            GDIGraphics3D graphics = new GDIGraphics3D(GraphicsConfig.BlackBackgroundCorrectForBackColor);

            Bitmap bitmap = ImageExporter.CreateAutoSizedBitmap(model,
                graphics, Matrix4D.Identity, System.Drawing.Color.White, maxSize);

            using (Stream stream = File.Create(fileName))
            {
                ImageExporter.EncodeImageToJpeg(bitmap, stream);
            }
        }
コード例 #15
0
        public static Bitmap CreateBitmap(
            GDIGraphics3D cadGraphics,
            SmoothingMode smoothingMode,
            Matrix4D transform,
            int width,
            int height)
        {
            Bitmap bitmap = new Bitmap(width, height);

            using (Graphics graphics = Graphics.FromImage((Image)bitmap))
            {
                graphics.SmoothingMode = smoothingMode;
                graphics.Clear((System.Drawing.Color)cadGraphics.GraphicsConfig.BackColor);
                cadGraphics.Draw(graphics, new Rectangle(0, 0, width, height), transform);
            }
            return(bitmap);
        }
コード例 #16
0
        private void OpenDxfFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "AutoCad files (*.dwg, *.dxf)|*.dxf;*.dwg";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                filename = dialog.FileName;
            }
            if (!string.IsNullOrEmpty(filename))
            {
                //this.xtraTabPage1.BackColor = System.Drawing.Color.Black;
                try
                {
                    //通过文件扩展名判断CAD文件是dwg格式还是dxf格式
                    string extension = Path.GetExtension(filename);
                    if (string.Compare(extension, ".dwg", true) == 0)
                    {
                        model = DwgReader.Read(filename);
                    }
                    else
                    {
                        model = DxfReader.Read(filename);
                    }
                    //将控件的标签添加上文件名
                    this.xtraTabPage1.Text = "二维仿真(" + Path.GetFileName(filename) + ")";
                    //设置控件背景为黑色
                    this.xtraTabPage1.BackColor = System.Drawing.Color.Black;

                    //使用GDIGraphics3D绘制CAD文件的方法
                    //创建中间可绘制对象
                    gdiGraphics3D = new GDIGraphics3D(GraphicsConfig.BlackBackgroundCorrectForBackColor);
                    gdiGraphics3D.CreateDrawables(model);
                    //获得bounding box
                    bounds = new Bounds3D();
                    gdiGraphics3D.BoundingBox(bounds, modelTransform);
                    //计算GDIGraphics3D的属性To2DTransform
                    CalculateTo2DTransform();
                    //响应控件的Paint事件,画CAD文件
                }
                catch (Exception ex)
                {
                    MessageBox.Show("文件有错!请用AutoCad打开,通过“文件-核查”尝试修复。错误信息:" + ex.Message);
                }
            }
        }
コード例 #17
0
ファイル: CADHelper.cs プロジェクト: kamchung322/Namwah
        public static void ExportToJpg(string sourceFile, string destName, Size maxSize)
        {
            DxfModel model = DwgReader.Read(sourceFile);
            GDIGraphics3D graphics = new GDIGraphics3D(GraphicsConfig.BlackBackgroundCorrectForBackColor);

            Bitmap bitmap = ImageExporter.CreateAutoSizedBitmap(model,
                graphics, Matrix4D.Identity, System.Drawing.Color.White, maxSize);

            if (File.Exists(destName))
            {
                File.Delete(destName);
            }

            using (Stream stream = File.Create(destName))
            {
                ImageExporter.EncodeImageToJpeg(bitmap, stream);
            }
        }
コード例 #18
0
        public static Bitmap CreateBitmap(
            DxfModel model,
            Matrix4D transform,
            GraphicsConfig graphicsConfig,
            SmoothingMode smoothingMode,
            int width,
            int height)
        {
            Bitmap bitmap = new Bitmap(width, height);

            using (Graphics graphics = Graphics.FromImage((Image)bitmap))
            {
                graphics.SmoothingMode = smoothingMode;
                graphics.Clear((System.Drawing.Color)graphicsConfig.BackColor);
                GDIGraphics3D gdiGraphics3D = new GDIGraphics3D(graphicsConfig);
                gdiGraphics3D.CreateDrawables(model);
                gdiGraphics3D.Draw(graphics, new Rectangle(0, 0, width, height), transform);
            }
            return(bitmap);
        }
コード例 #19
0
        public static Bitmap CreateAutoSizedBitmap(
            GDIGraphics3D cadGraphics,
            SmoothingMode smoothingMode,
            Matrix4D transform,
            System.Drawing.Color backColor)
        {
            transform = Transformation4D.Translation(2.0, 2.0, 0.0) * transform;
            Bounds3D bounds = new Bounds3D();

            cadGraphics.BoundingBox(bounds, transform);
            if (!bounds.Initialized)
            {
                return(ImageExporter.CreateEmptyBitmap(backColor, 1, 1));
            }
            WW.Math.Vector3D delta      = bounds.Delta;
            Matrix4D         transform1 = DxfUtil.GetScaleTransform(bounds.Min, bounds.Max, new WW.Math.Point3D(2.0, delta.Y + 2.0, 0.0), new WW.Math.Point3D(delta.X + 2.0, 2.0, 0.0)) * transform;
            int width  = (int)System.Math.Ceiling(delta.X) + 4;
            int height = (int)System.Math.Ceiling(delta.Y) + 4;

            return(ImageExporter.CreateBitmap(cadGraphics, smoothingMode, transform1, backColor, width, height));
        }
コード例 #20
0
        public static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                args = new string[2];
                //args[1] = "D:\\C项目\\CadLCmd\\CadLCmd\\dwg\\test1.dwg";
                //args[1] = "D:\\C项目\\CadLCmd\\CadLCmd\\dwg\\test2.dwg";
                //args[1] = "D:\\C项目\\CadLCmd\\CadLCmd\\dwg\\test3.dwg";
                //args[1] = "D:\\C项目\\CadLCmd\\CadLCmd\\dwg\\test4.dwg";
                args[1] = "D:\\C项目\\CadLCmd\\CadLCmd\\dwg\\test5Insert.dwg";
                //args[1] = "D:\\C项目\\CadLCmd\\CadLCmd\\dwg\\test6.dwg";
            }
            string format   = args[0];
            string filename = args[1];

            DxfModel model = null;

            try
            {
                string extension = Path.GetExtension(filename);
                if (string.Compare(extension, ".dwg", true) == 0)
                {
                    model = DwgReader.Read(filename);
                }
                else
                {
                    model = DxfReader.Read(filename);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Error occurred: " + e.Message);
                Environment.Exit(1);
            }

            //foreach (var entityGroups in model.Entities.GroupBy(a => a.GetType()))
            //{

            //    Console.WriteLine(entityGroups.GetType());

            //    //if (typeof(DxfLine) == entityGroups.Key)
            //    //{
            //    //    foreach (var item in entityGroups)
            //    //    {
            //    //        Console.WriteLine(item.Color);

            //    //    }
            //    //}

            //}
            //FileStream fs = new FileStream("D:\\C项目\\CadLCmd\\CadLCmd\\txt\\test1.txt", FileMode.Create);



            FindEntities(model.Entities);



            string json = JsonConvert.SerializeObject(cadEntities);

            File.WriteAllText("D:\\C项目\\CadLCmd\\CadLCmd\\txt\\model.json", json);
            File.WriteAllText("D:\\Project\\cadtest\\node_modules\\@cadTestUbim\\res\\data\\dxfdata.json", json);

            //清空缓冲区
            sw.Flush();
            //关闭流
            sw.Close();
            fs.Close();

            KTCodes = ktls.ToArray();

            KTest = ktest.ToArray();

            DxfType = dxfType.ToArray();

            KInsert = kins.ToArray();

            KEC = kco.ToArray();

            KCIRCLE = kcircle.ToArray();

            //Console.ReadKey();
            string outfile = Path.GetDirectoryName(Path.GetFullPath(filename)) + "\\12";
            Stream stream;

            if (format == "pdf")
            {
                BoundsCalculator boundsCalculator = new BoundsCalculator();
                boundsCalculator.GetBounds(model);
                Bounds3D  bounds    = boundsCalculator.Bounds;
                PaperSize paperSize = PaperSizes.GetPaperSize(PaperKind.Letter);
                // Lengths in inches.
                float pageWidth  = (float)paperSize.Width / 100f;
                float pageHeight = (float)paperSize.Height / 100f;
                float margin     = 0.5f;
                // Scale and transform such that its fits max width/height
                // and the top left middle of the cad drawing will match the
                // top middle of the pdf page.
                // The transform transforms to pdf pixels.
                Matrix4D to2DTransform = DxfUtil.GetScaleTransform(
                    bounds.Corner1,
                    bounds.Corner2,
                    new Point3D(bounds.Center.X, bounds.Corner2.Y, 0d),
                    new Point3D(new Vector3D(margin, margin, 0d) * PdfExporter.InchToPixel),
                    new Point3D(new Vector3D(pageWidth - margin, pageHeight - margin, 0d) * PdfExporter.InchToPixel),
                    new Point3D(new Vector3D(pageWidth / 2d, pageHeight - margin, 0d) * PdfExporter.InchToPixel)
                    );
                using (stream = File.Create(outfile + ".pdf"))
                {
                    PdfExporter pdfGraphics = new PdfExporter(stream);
                    pdfGraphics.DrawPage(
                        model,
                        GraphicsConfig.WhiteBackgroundCorrectForBackColor,
                        to2DTransform,
                        paperSize
                        );
                    pdfGraphics.EndDocument();
                }
            }
            else
            {
                GDIGraphics3D graphics = new GDIGraphics3D(GraphicsConfig.BlackBackgroundCorrectForBackColor);
                Size          maxSize  = new Size(500, 500);
                Bitmap        bitmap   =
                    ImageExporter.CreateAutoSizedBitmap(
                        model,
                        graphics,
                        Matrix4D.Identity,
                        System.Drawing.Color.Black,
                        maxSize
                        );
                switch (format)
                {
                case "bmp":
                    using (stream = File.Create(outfile + ".bmp"))
                    {
                        ImageExporter.EncodeImageToBmp(bitmap, stream);
                    }
                    break;

                case "gif":
                    using (stream = File.Create(outfile + ".gif"))
                    {
                        ImageExporter.EncodeImageToGif(bitmap, stream);
                    }
                    break;

                case "tiff":
                    using (stream = File.Create(outfile + ".tiff"))
                    {
                        ImageExporter.EncodeImageToTiff(bitmap, stream);
                    }
                    break;

                case "png":
                    using (stream = File.Create(outfile + ".png"))
                    {
                        ImageExporter.EncodeImageToPng(bitmap, stream);
                    }
                    break;

                case "jpg":
                    using (stream = File.Create(outfile + ".jpg"))
                    {
                        ImageExporter.EncodeImageToJpeg(bitmap, stream);
                    }
                    break;

                default:
                    Console.WriteLine("Unknown format " + format + ".");
                    break;
                }
            }
        }
コード例 #21
0
ファイル: ViewControl.cs プロジェクト: Spritutu/ntxx
        public void initParameter()
        {
            model=null;
            gdiGraphics3D=null;
            bounds=null;
            //Matrix4D tempfrom2DTransform;
            //from2DTransform=tempfrom2DTransform;
            //Point tempmouseClickLocation;
            //mouseClickLocation=tempmouseClickLocation;
            mouseDown=false;
            shiftPressed=false;

            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.UserPaint, true);
            GraphicsConfig graphicsConfig = new GraphicsConfig();
            //graphicsConfig.BackColor = BackColor;
            graphicsConfig.CorrectColorForBackgroundColor = true;
            gdiGraphics3D = new GDIGraphics3D(graphicsConfig);
            bounds = new Bounds3D();

            transformationProvider = new SimpleTransformationProvider3D();
            transformationProvider.TransformsChanged += new EventHandler(transformationProvider_TransformsChanged);
            panInteractor = new SimplePanInteractor(transformationProvider);
            rectZoomInteractor = new SimpleRectZoomInteractor(transformationProvider);
            zoomWheelInteractor = new SimpleZoomWheelInteractor(transformationProvider);
            rectZoomInteractorDrawable = new SimpleRectZoomInteractor.WinFormsDrawable(rectZoomInteractor);
        }
コード例 #22
0
        public void getDXFFormat(DxfModel model, string filename, string outfile)
        {
            try
            {
                string extension = System.IO.Path.GetExtension(filename);
                if (string.Compare(extension, ".dwg", true) == 0)
                {
                    model = DwgReader.Read(filename);
                }
                else
                {
                    model = DxfReader.Read(filename);
                }
            }
            catch (Exception e)
            {
                //Console.Error.WriteLine("Error occurred: " + e.Message);
                //Environment.Exit(1);
            }

            GDIGraphics3D graphics = new GDIGraphics3D(GraphicsConfig.BlackBackgroundCorrectForBackColor);
            Size          maxSize  = new Size(500, 500);
            Bitmap        bitmap   =
                ImageExporter.CreateAutoSizedBitmap(
                    model,
                    graphics,
                    Matrix4D.Identity,
                    System.Drawing.Color.Black,
                    maxSize
                    );
            //string outfile = Path.GetFileNameWithoutExtension(Path.GetFullPath(filename));
            Stream stream = null;
            //string outfile = AppDomain.CurrentDomain.BaseDirectory + "Drill\\rockHistogram\\"+filename;

            BoundsCalculator boundsCalculator = new BoundsCalculator();

            boundsCalculator.GetBounds(model);
            Bounds3D  bounds    = boundsCalculator.Bounds;
            PaperSize paperSize = PaperSizes.GetPaperSize(PaperKind.A4);//设置为A4纸的大小
            // Lengths in inches.
            float pageWidth  = (float)paperSize.Width / 100f;
            float pageHeight = (float)paperSize.Height / 100f;
            float margin     = 0.2f; //值越小 model相对于pdf图幅越大
            // Scale and transform such that its fits max width/height
            // and the top left middle of the cad drawing will match the
            // top middle of the pdf page.
            // The transform transforms to pdf pixels.
            Matrix4D to2DTransform = DxfUtil.GetScaleTransform(
                bounds.Corner1,
                bounds.Corner2,
                new Point3D(bounds.Center.X, bounds.Corner2.Y, 0d),
                new Point3D(new Vector3D(margin, margin, 0d) * PdfExporter.InchToPixel),
                new Point3D(new Vector3D(pageWidth - margin, pageHeight - margin, 0d) * PdfExporter.InchToPixel),
                new Point3D(new Vector3D(pageWidth / 2d, pageHeight - margin, 0d) * PdfExporter.InchToPixel)
                );

            using (stream = File.Create(outfile + ".pdf"))
            {
                PdfExporter pdfGraphics = new PdfExporter(stream);
                pdfGraphics.DrawPage(
                    model,
                    GraphicsConfig.WhiteBackgroundCorrectForBackColor,
                    to2DTransform,
                    paperSize
                    );
                pdfGraphics.EndDocument();
            }

            /*
             * 可选的图片格式
             * stream = File.Create(outfile + ".png");
             * ImageExporter.EncodeImageToPng(bitmap, stream);
             *
             * stream = File.Create(outfile + ".tiff");
             * ImageExporter.EncodeImageToTiff(bitmap, stream);
             *
             * stream = File.Create(outfile + ".jpg");
             * ImageExporter.EncodeImageToJpeg(bitmap, stream);
             *
             * stream = File.Create(outfile + ".gif");
             * ImageExporter.EncodeImageToGif(bitmap, stream);
             *
             * stream = File.Create(outfile + ".bmp");
             * ImageExporter.EncodeImageToBmp(bitmap, stream);
             */
        }
コード例 #23
0
ファイル: ShowDwgFile.cs プロジェクト: sunjini/ShowDwgFile
 public ShowDwgFile()
 {
     ImageControl  = this;
     gdiGraphics3D = new GDIGraphics3D(GraphicsConfig.BlackBackgroundCorrectForBackColor);
     //InitializeComponent();
 }