Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
		/*public static void initMaxPt()
		{
			maxX=Double.MinValue;
			minX=Double.MaxValue;
			maxY=Double.MinValue;
			minY=Double.MaxValue;
		}*/
		
		
		public static Vector2 getBlockCenter()
		{
			DimMax dim = GetLastMaxDim();
			Vector2 v1 = new Vector2(dim.minX,dim.minY);
			Vector2 v2 = new Vector2(dim.maxX,dim.maxY);
			Vector2 vres = (v1+v2)/2;
			
			return vres;
		}
Exemplo n.º 3
0
		/*Draw Insert*/
		public static void DrawInsert(Insert xInsert, Canvas mainCanvas)
		{
			xInsert.Block.Layer = xInsert.Layer;
			Canvas canvas1 = new Canvas();
			
			AddNewMaxDim();
			canvas1 = GetBlock(xInsert.Block, xInsert.Color, xInsert.Lineweight);
			DimMax dim = GetLastMaxDim();

			mainCanvas.Children.Add(canvas1);
			double x1,x2,y1,y2;
			
			
			
			Vector2 vCenter = getBlockCenter();
			
			
			x1 = dim.maxX*xInsert.Scale.X+xInsert.Position.X;
			y1 = dim.maxY*xInsert.Scale.Y+xInsert.Position.Y;
			x2= dim.minX*xInsert.Scale.X+xInsert.Position.X;
			y2 = dim.minY*xInsert.Scale.Y+xInsert.Position.Y;
			
			dim.maxX = Math.Max(x1,x2);
			dim.minX = Math.Min(x1,x2);
			dim.maxY = Math.Max(y1,y2);
			dim.minY = Math.Min(y1,y2);
			
			Canvas.SetLeft(canvas1, xInsert.Position.X);
			//if (xInsert.Scale.X < 0) Canvas.SetLeft(canvas1, dim.maxX);
			Canvas.SetTop(canvas1, mainCanvas.Height - (xInsert.Position.Y + canvas1.Height));
			//if (xInsert.Scale.Y < 0) Canvas.SetTop(canvas1, mainCanvas.Height - (dim.maxY));;
			
			TransformGroup trgr = new TransformGroup();
			canvas1.RenderTransform = trgr;
			if(xInsert.Rotation != 0.0)
			{
				trgr.Children.Add(new RotateTransform(xInsert.Rotation,0,0));

			}
			
			if((xInsert.Scale.X != 1.0 ||xInsert.Scale.Y != 1.0) && xInsert.Scale.X != 0 && xInsert.Scale.Y != 0)
			{
				trgr.Children.Add(new ScaleTransform(xInsert.Scale.X,xInsert.Scale.Y,0,0));
			}

			
			foreach (netDxf.Entities.Attribute xAttrib in xInsert.Attributes) {
				xAttrib.Layer = xInsert.Layer;
				DrawAttribute(xAttrib, mainCanvas);
			}
			
			

		}
Exemplo n.º 4
0
		public static void getMaxPt(System.Windows.Point pt)
		{
			DimMax dim = GetLastMaxDim();
			if (dim != null)
			{
				if(pt.X > dim.maxX) dim.maxX=pt.X;
				if(pt.Y > dim.maxY) dim.maxY=pt.Y;
				if(pt.X < dim.minX) dim.minX=pt.X;
				if(pt.Y < dim.minY) dim.minY=pt.Y;
			}
			
		}
Exemplo n.º 5
0
		public static void AddNewMaxDim()
		{
			DimMax newDim = new DimMax();
			listDim.Add(newDim);
		}