public static RenderTargetBitmap GetImage(Canvas canvas, double scale = 1.0, bool avecFond = false)
        {
            DrawEntities.CalcMaxDimDoc();
            DimMax dim = DrawEntities.dimDoc;



            Size size = new Size(dim.Width(), dim.Height());

            //Size size = new Size(1000, 1000);
            //System.Windows.Point p0 = new System.Windows.Point(0,-200);
            System.Windows.Point p0 = new System.Windows.Point(dim.minX, dim.minY);
            if (size.IsEmpty)
            {
                return(null);
            }

            //RenderTargetBitmap result = new RenderTargetBitmap((int)size.Width*2, (int)size.Height*2, 96*2, 96*2, PixelFormats.Pbgra32);
            RenderTargetBitmap result = new RenderTargetBitmap((int)(size.Width * scale), (int)(size.Height * scale), 96 * scale, 96 * scale, PixelFormats.Default);

            DrawingVisual drawingvisual = new DrawingVisual();

            using (DrawingContext context = drawingvisual.RenderOpen())
            {
                if (avecFond)
                {
                    context.DrawRectangle(Brushes.White, null, new Rect(p0, size));
                }
                context.DrawRectangle(new VisualBrush(canvas), null, new Rect(p0, size));
                context.Close();
            }

            result.Render(drawingvisual);
            return(result);
        }
 public static System.Windows.Point Vertex2ToPoint(Vector2 V2, double CanvasHeight)
 {
     DrawEntities.getMaxPt(V2);
     System.Windows.Point newPoint = new System.Windows.Point();
     newPoint.X = V2.X;
     newPoint.Y = CanvasHeight - V2.Y;
     return(newPoint);
 }
 public static System.Windows.Point Vertex3ToPoint(Vector3 V3, double CanvasHeight)
 {
     DrawEntities.getMaxPt(V3);
     System.Windows.Point newPoint = new System.Windows.Point();
     newPoint.X = V3.X;
     newPoint.Y = CanvasHeight - V3.Y;
     return(newPoint);
 }
        public void ZoomAuto(double gridHeight, double gridWidth, double WinHeight, double WinWidth)
        {
            if (_child != null)
            {
                double hauteurVu;
                double largeurVu;
                double hauteurUtil;
                double largeurUtil;
                double scaleY;
                double scaleX;
                double scale;

                DrawEntities.CalcMaxDimDoc();
                if (DrawEntities.dimDoc.maxY == double.MinValue || DrawEntities.dimDoc.maxX == double.MinValue)
                {
                    return;
                }
                hauteurVu = Math.Abs(DrawEntities.dimDoc.maxY - DrawEntities.dimDoc.minY);
                largeurVu = Math.Abs(DrawEntities.dimDoc.maxX - DrawEntities.dimDoc.minX);

                scaleY = (WinHeight) / (hauteurVu);
                scaleX = WinWidth / (largeurVu);

                scale = Math.Min(scaleY, scaleX);
                scale = Scale;// 修改比例

                if (scale == 0)
                {
                    scale     = 1.0;
                    hauteurVu = 462;
                }

                hauteurUtil = WinHeight - hauteurVu * scale;
                largeurUtil = WinWidth - largeurVu * scale;

                var tt = GetTranslateTransform(_child);

                tt.X = -gridWidth * scale / 2 - DrawEntities.dimDoc.minX * scale;
                tt.Y = -(gridHeight * scale) / 2 - 250 * scale + (WinHeight) + DrawEntities.dimDoc.minY * scale;

                var st = GetScaleTransform(_child);

                st.ScaleX = Math.Abs(scale);
                st.ScaleY = Math.Abs(scale);
            }
        }
        public void Reset(double gridHeight, double gridWidth, bool init, double ViewHeight, double ViewWidth, double WinHeight, double WinWidth)
        {
            if (_child != null)
            {
                double hauteurVu;
                double largeurVu;
                double scaleY;
                double scaleX;
                double scale;

                DrawEntities.CalcMaxDimDoc();



                if (init == true)
                {
                    hauteurVu = ViewHeight;
                    largeurVu = ViewWidth;

                    if (hauteurVu == 0.0)
                    {
                        hauteurVu = 462;
                    }
                    if (largeurVu == 0.0)
                    {
                        largeurVu = 500;
                    }
                }
                else
                {
                    hauteurVu = DrawEntities.dimDoc.maxY - DrawEntities.dimDoc.minY;
                    largeurVu = DrawEntities.dimDoc.maxX - DrawEntities.dimDoc.minX;
                }

                scaleY = ViewHeight / hauteurVu;
                scaleX = ViewWidth / largeurVu;
                scale  = Math.Min(scaleY, scaleX);
                scale  = Scale;// 修改比例

                if (scale == 0)
                {
                    scale = 1.0;
                }
                var st = GetScaleTransform(_child);

                st.ScaleX = scale;
                st.ScaleY = scale;
                var tt = GetTranslateTransform(_child);

                if (WinHeight == 0)
                {
                    WinHeight = ViewHeight;
                }
                if (WinWidth == 0)
                {
                    WinWidth = ViewWidth;
                }

                if (init == true)
                {
                    tt.X = -gridWidth * scale / 2;
                    tt.Y = -gridHeight * scale / 2;
                }
                else
                {
                    tt.X = -gridWidth * scale / 2 - DrawEntities.dimDoc.minX * scale;
                    tt.Y = -gridHeight * scale / 2 - (WinHeight * scale) / 2 + hauteurVu * scale + DrawEntities.dimDoc.minY * scale;
                }
            }
        }
        public Grid mainGrid     = new Grid();   //面板 grid

        public Grid GetMainGrid(netDxf.DxfDocument dxfFile, bool avecGrille, bool avecOrigine, Color bgColor)
        {
            try
            {
                mainCanvas.Children.Clear();
                DrawEntities.RazMaxDim();
                DrawEntities.AddNewMaxDim();

                ;
                //  mainGrid = new Grid();
                mainGrid.HorizontalAlignment = HorizontalAlignment.Stretch;
                mainGrid.VerticalAlignment   = VerticalAlignment.Stretch;


                Color m_Color = Color.FromArgb(255, (byte)128, (byte)128, (byte)128);
                mainGrid.Background = new SolidColorBrush(m_Color);


                border.Height = GridHeight;
                border.Width  = GridWidth;
                //

                border.Background          = new SolidColorBrush(m_Color); //UNdone::取消背景颜色
                border.HorizontalAlignment = HorizontalAlignment.Stretch;
                border.VerticalAlignment   = VerticalAlignment.Stretch;
                border.Scale = Scale;//增加比例


                mainCanvas.Name = "mainCanvas";
                if (DxfDoc.DrawingVariables.AcadVer < netDxf.Header.DxfVersion.AutoCad2000)
                {
                    DrawUtils.DrawText("Le format du fichier doit être dxf2000 ou supérieur.", 10, Colors.Red, 20, 50, mainCanvas);
                }
                GetCanvas(DxfDoc, mainCanvas);

                if (avecOrigine == true)
                {
                    DrawEntities.AddNewMaxDim();
                    DrawUtils.DrawOrigin(mainCanvas);
                    DrawEntities.DeleteLastMaxDim();
                }

                if (avecGrille == true)
                {
                    Canvas bgCanvas = new Canvas();
                    if (border.Child == null)
                    {
                        bgCanvas = CreateBgCanvas();
                        bgCanvas.Children.Add(mainCanvas);

                        border.Child = bgCanvas;
                    }
                }
                else
                {
                    border.Child = mainCanvas;
                }

                Canvas.SetTop(mainCanvas, GridHeight / 2);
                Canvas.SetLeft(mainCanvas, GridWidth / 2);

                //  Canvas.SetTop(mainCanvas, 0);
                //  Canvas.SetLeft(mainCanvas, 0);

                //border.Reset(GridHeight,GridWidth,true,ViewHeight,ViewWidth,WinHeight,WinWidth);



                if (mainGrid.Children.Count == 0)
                {
                    //bool res = mainGrid.Children.Contains(border);
                    // if(res==false)
                    mainGrid.Children.Add(border);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


            return(mainGrid);
        }
        public static void GetCanvas(netDxf.DxfDocument DxfDoc, Canvas mainCanvas)
        {
            mainCanvas.Width  = 250;
            mainCanvas.Height = 250;



            /*Dessin Line*/
            Debug.WriteLine("nb ligne=" + DxfDoc.Lines);
            foreach (netDxf.Entities.Line xLine in DxfDoc.Lines)
            {
                DrawEntities.DrawLine(xLine, mainCanvas);
            }

            /*Dessin Polyline*/
            //Debug.WriteLine("nb Polyline="+DxfDoc.Polylines.Count.ToString());
            foreach (netDxf.Entities.Polyline xPoly in DxfDoc.Polylines)
            {
                DrawEntities.DrawPolyline(xPoly, mainCanvas);
            }

            /*Dessin LwPolyline*/
            //Debug.WriteLine("nb LwPolyligne="+DxfDoc.LwPolylines.Count.ToString());
            foreach (netDxf.Entities.LwPolyline xPoly in DxfDoc.LwPolylines)
            {
                DrawEntities.DrawLwPolyline(xPoly, mainCanvas);
            }

            /*Dessin Mlines*/
            //Debug.WriteLine("nb MLines="+DxfDoc.MLines.Count.ToString());
            foreach (netDxf.Entities.MLine xPoly in DxfDoc.MLines)
            {
                DrawEntities.DrawMLine(xPoly, mainCanvas);
            }

            /*Dessin Solid*/
            //Debug.WriteLine("nb Solids="+DxfDoc.Solids.Count.ToString());
            foreach (netDxf.Entities.Solid xPoly in DxfDoc.Solids)
            {
                DrawEntities.DrawSolid(xPoly, mainCanvas);
            }

            /*Dessin PolyfaceMesh*/
            //Debug.WriteLine("nb PolyfaceMesh="+DxfDoc.PolyfaceMeshes.Count.ToString());
            foreach (netDxf.Entities.PolyfaceMesh xPoly in DxfDoc.PolyfaceMeshes)
            {
                DrawEntities.DrawPolyfaceMesh(xPoly, mainCanvas);
            }

            /*Dessin Wipeout*/
            //Debug.WriteLine("nb Wipeout="+DxfDoc.PolyfaceMeshes.Count.ToString());
            foreach (netDxf.Entities.Wipeout xPoly in DxfDoc.Wipeouts)
            {
                DrawEntities.DrawWipeout(xPoly, mainCanvas);
            }

            /*Dessin Face3D*/
            //Debug.WriteLine("nb Face3D="+DxfDoc.Faces3d.Count.ToString());
            foreach (netDxf.Entities.Face3d xPoly in DxfDoc.Faces3d)
            {
                DrawEntities.DrawFace3d(xPoly, mainCanvas);
            }

            /*Dessin Circle*/
            //Debug.WriteLine("nb Circles="+DxfDoc.Circles.Count.ToString());
            foreach (netDxf.Entities.Circle xCircle in DxfDoc.Circles)
            {
                DrawEntities.DrawCircle(xCircle, mainCanvas);
            }

            /*Dessin Ellipse*/
            //Debug.WriteLine("nb Ellipses="+DxfDoc.Ellipses.Count.ToString());
            foreach (netDxf.Entities.Ellipse xEllipse in DxfDoc.Ellipses)
            {
                DrawEntities.DrawEllipse(xEllipse, mainCanvas);
            }

            /*Dessin Arc*/
            //Debug.WriteLine("nb Arcs="+DxfDoc.Arcs.Count.ToString());
            foreach (netDxf.Entities.Arc xArc in DxfDoc.Arcs)
            {
                DrawEntities.DrawArc(xArc, mainCanvas);
            }

            /*Dessin Text*/
            //Debug.WriteLine("nb Text="+DxfDoc.Texts.Count.ToString());
            foreach (netDxf.Entities.Text xTxt in DxfDoc.Texts)
            {
                DrawEntities.DrawText(xTxt, mainCanvas);
            }

            /*Dessin MText*/
            //Debug.WriteLine("nb MText="+DxfDoc.MTexts.Count.ToString());
            foreach (netDxf.Entities.MText xTxt in DxfDoc.MTexts)
            {
                Debug.WriteLine("Reactor=" + xTxt.Reactors.Count.ToString());
                if (xTxt.Reactors.Count == 0)
                {
                    DrawEntities.DrawMText(xTxt, mainCanvas);
                }
            }


            /*Dessin Point*/
            //	Debug.WriteLine("nb Points="+DxfDoc.Points.Count().ToString());
            foreach (netDxf.Entities.Point xPoint in DxfDoc.Points)
            {
                DrawEntities.DrawPoint(xPoint, mainCanvas);
            }


            /*Dessin Dimension*/
            //Debug.WriteLine("nb Dimensions="+DxfDoc.Dimensions.Count.ToString());
            foreach (netDxf.Entities.Dimension xDim in DxfDoc.Dimensions)
            {
                xDim.Lineweight = Lineweight.W0;
                DrawEntities.DrawDimension(xDim, mainCanvas);
            }

            /*Dessin Insert*/
            //Debug.WriteLine("nb Insert="+DxfDoc.Inserts.Count.ToString());
            foreach (netDxf.Entities.Insert xInsert in DxfDoc.Inserts)
            {
                DrawEntities.DrawInsert(xInsert, mainCanvas);
            }


            /*Dessin Leader*/
            //Debug.WriteLine("nb Leader="+DxfDoc.Leaders.Count.ToString());
            foreach (netDxf.Entities.Leader xLeader in DxfDoc.Leaders)
            {
                DrawEntities.DrawLeader(xLeader, mainCanvas);
            }


            /*Dessin Spline*/
            //Debug.WriteLine("nb Spline="+DxfDoc.Splines.Count.ToString());
            foreach (netDxf.Entities.Spline xSpline in DxfDoc.Splines)
            {
                DrawEntities.DrawSpline(xSpline, mainCanvas);
            }



            /*Dessin Hatch*/
            //Debug.WriteLine("nb Hatch="+DxfDoc.Hatches.Count.ToString());
            foreach (netDxf.Entities.Hatch xHatch in DxfDoc.Hatches)
            {
                DrawEntities.DrawHatch(xHatch, mainCanvas);
            }


            /*Dessin Image*/
            //Debug.WriteLine("nb Image="+DxfDoc.Images.Count.ToString());
            foreach (netDxf.Entities.Image xImage in DxfDoc.Images)
            {
                DrawEntities.DrawImage(xImage, mainCanvas);
            }


            /*Dessin Underlay*/
            //Debug.WriteLine("nb Underlay="+DxfDoc.Underlays.Count.ToString());
            foreach (netDxf.Entities.Underlay xUnderlay in DxfDoc.Underlays)
            {
                DrawEntities.DrawUnderlay(xUnderlay, mainCanvas);
            }


            /*Dessin Mesh*/
            //Debug.WriteLine("nb Mesh="+DxfDoc.Meshes.Count.ToString());
            foreach (netDxf.Entities.Mesh xMesh in DxfDoc.Meshes)
            {
                DrawEntities.DrawMesh(xMesh, mainCanvas);
            }

            /*Debug.WriteLine("DXFDoc:"+DxfDoc.DrawingVariables.LUnits.ToString());
             * Debug.WriteLine("DXFDoc TextSize:"+DxfDoc.DrawingVariables.TextSize.ToString());
             * Debug.WriteLine("DXFDoc InsUnits:"+DxfDoc.DrawingVariables.InsUnits.ToString());*/
        }