Clone() public method

public Clone ( ) : Matrix
return Matrix
Example #1
0
        public static void SetGraphTransform(Graph graph, Graphics graphics)
        {
            var pen = new Pen(Brushes.Black);

            using (System.Drawing.Drawing2D.Matrix m = graphics.Transform)
            {
                using (System.Drawing.Drawing2D.Matrix saveM = m.Clone())
                {
                    foreach (Microsoft.Msagl.Drawing.Node node in graph.Nodes)
                    {
                        graphics.SetClip(FillTheGraphicsPath(node.GeometryNode.BoundaryCurve));
                        using (var m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * (float)node.GeometryNode.Center.Y))
                            m.Multiply(m2);
                        graphics.DrawLine(pen, PointF(node.GeometryNode.Center),
                                          PointF(new Microsoft.Msagl.Core.Geometry.Point((int)node.GeometryNode.Center.X + 20,
                                                                                         (int)node.GeometryNode.Center.Y + 20)));
                        graphics.Transform = m;
                        graphics.Transform = saveM;
                        graphics.ResetClip();
                    }
                }
            }

            /*
             * //instead of setting transormation for graphics it is possible to transform the geometry graph, just to test that GeometryGraph.Transform() works
             *
             * var planeTransformation=new PlaneTransformation(scale,0,dx, 0, scale, dy);
             * geometryGraph.Transform(planeTransformation);
             */
            // graphics.Transform = new Matrix((float)scale, 0, 0, (float)scale, (float)dx, (float)dy);
        }
Example #2
0
        /// <summary>
        /// Рисует границу узла
        /// </summary>
        /// <param name="node"></param>
        /// <param name="graphics"></param>
        /// <returns></returns>
        private bool DrawNode(Node node, object graphics)
        {
            Graphics g = (Graphics)graphics;
            //возвращает рисунок
            Image image = ImageOfNode(node);

            //flip the image around its center
            using (System.Drawing.Drawing2D.Matrix m = g.Transform)
            {
                using (System.Drawing.Drawing2D.Matrix saveM = m.Clone())
                {
                    g.SetClip(FillTheGraphicsPath(node.GeometryNode.BoundaryCurve));
                    using (var m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * (float)node.GeometryNode.Center.Y))
                        m.Multiply(m2);

                    g.Transform = m;
                    g.DrawImage(image, new PointF((float)(node.GeometryNode.Center.X - node.GeometryNode.Width / 2),
                                                  (float)(node.GeometryNode.Center.Y - node.GeometryNode.Height / 2)));
                    g.Transform = saveM;
                    g.ResetClip();
                }
            }

            return(true);//returning false would enable the default rendering
        }
        /// <summary>
        /// Snap translation part of the matrix to a given vector.
        /// </summary>
        /// <param name="mat"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static d2d.Matrix eSnapTranslate(this d2d.Matrix mat, double x, double y)
        {
            var curmat = mat.Elements;
            var newmat = new d2d.Matrix(curmat[0], curmat[1]
                                        , curmat[2], curmat[3]
                                        , (float)x, (float)y);

            return(newmat.Clone());
        }
Example #4
0
        void generateTransformMat()
        {
            mTransformMat = new Matrix();
            mTransformMat.Translate(mTranslation.X, mTranslation.Y);
            mTransformMat.Scale(mZoomAmt.Value, mZoomAmt.Value, MatrixOrder.Append);

            mTransformMatInv = mTransformMat.Clone();
            mTransformMatInv.Invert();
        }
Example #5
0
 /// <summary>
 /// Will return a copy of the Transform currently used to map the world Space of the draw Set to the pixel Space of the screen
 /// </summary>
 /// <returns></returns>
 public void setInverseCameraTransform()
 {
     inverseCameraTransform = cameraTransform.Clone();
     inverseCameraTransform.Invert();
     //adjusting for any warping as a result of differently sized buffers
     if (drawBuffers != null && (drawBuffers[0].Width != base.Width || drawBuffers[0].Height != base.Height))
     {
         inverseCameraTransform.Scale(base.Width / drawBuffers[0].Width, base.Height / drawBuffers[0].Height, MatrixOrder.Append);
     }
 }
        void Parent_PCBIFormGraphicPaneDrawing(Graphics g, int ClientWidth, int ClientHeight)
        {
            if (!parent.JobIsLoaded)
            {
                return;
            }
            int   pcbCount  = 0;
            IStep PanelStep = parent.GetCurrentStep();

            if (PanelStep == null)
            {
                return;
            }

            RectangleF PanelSize = PanelStep.GetBounds();

            if (PanelSize == RectangleF.Empty)
            {
                return;
            }
            DrawSingleBoard(g, PanelSize, new PointD(0, 0), pcbCount, PanelStep.Name, "0");
            pcbCount++;
            List <IStep.StepAndRepeatClass> srList = PanelStep.GetChildStepClasses();

            foreach (IStep.StepAndRepeatClass sr in srList)
            {
                IStep step = parent.GetStep(sr.NAME);
                System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
                matrix.Rotate(-(float)sr.ANGLE, System.Drawing.Drawing2D.MatrixOrder.Append);
                matrix.Translate((float)sr.X, (float)sr.Y, System.Drawing.Drawing2D.MatrixOrder.Append);
                RectangleF BoardSize     = IMath.RectangleTransformWithMatrix(step.GetBoundsD(), matrix).ToRectangleF();
                PointD     originOfBoard = new PointD(sr.X, sr.Y);
                IMath.TransformPoint(matrix, originOfBoard);
                DrawSingleBoard(g, BoardSize, originOfBoard, pcbCount, sr.NAME, sr.ANGLE.ToString("N2"));
                if (sr.NX > 1 || sr.NY > 1)
                {
                    for (int iy = 0; iy < sr.NY; iy++)
                    {
                        for (int ix = 0; ix < sr.NX; ix++)
                        {
                            System.Drawing.Drawing2D.Matrix matrixsr = matrix.Clone();
                            double offsetX = sr.DX * ix;
                            double offsetY = sr.DY * iy;
                            matrixsr.Translate((float)offsetX, (float)offsetY, System.Drawing.Drawing2D.MatrixOrder.Append);
                            BoardSize     = IMath.RectangleTransformWithMatrix(step.GetBoundsD(), matrixsr).ToRectangleF();
                            originOfBoard = new PointD(sr.X + offsetX, sr.Y + offsetY);
                            DrawSingleBoard(g, BoardSize, originOfBoard, pcbCount, sr.NAME, sr.ANGLE.ToString("N2"));
                            pcbCount++;
                        }
                    }
                }
                pcbCount++;
            }
        }
Example #7
0
            /// <summary>
            /// Sets the View parameters so that the <see cref="PlotModel"/>'s bounds world coordinates transform to device
            /// coordinates will fit in to the <see cref="Rectangle"/> bounds.
            /// </summary>
            public void SetBounds(PlotModel Model, Rectangle bounds)
            {
                ResetBounds();
                RectangleF b = Bounds(Model);

                PointF[] v = new PointF[3];
                v[0].X = bounds.X; v[0].Y = bounds.Y;
                v[1].X = bounds.X + bounds.Width; v[1].Y = bounds.Y;
                v[2].X = bounds.X; v[2].Y = bounds.Y + bounds.Height;
                T2D    = new System.Drawing.Drawing2D.Matrix(b, v);
                T2Dinv = T2D.Clone();
                T2Dinv.Invert();
            }
    /// <summary>
    /// Gets rectangle required for a visible content
    /// </summary>
    static private RectangleF GetInvertedRect(RectangleF rect, Matrix transform)
    {
        var t = (System.Drawing.Drawing2D.Matrix)transform.Clone();

        t.Invert();

        using (var path = new Path())
        {
            path.DrawRectangle(rect);
            path.ApplyTransform(t);

            return(path.GetBounds());
        }
    }
Example #9
0
        /// <summary>
        /// Draw this shape onto a bitmap.
        /// </summary>
        /// <param name="graphics">Graphics object to draw with.</param>
        /// <param name="cache">Gdi cache.</param>
        public void DrawShape(Graphics graphics, GdiCache cache)
        {
            if (!IsValid)
            {
                return;
            }

            PointF point  = cache.Projection.MapToBitmap(Location);
            PointF anchor = point;

            Font font = cache.ParseFont(Font, out string _);

            if (font == null)
            {
                font = SystemFonts.CaptionFont;
            }

            Brush fill = new SolidBrush(Colour);
            SizeF size = graphics.MeasureString(Text, font);

            point.X -= 0.5f * size.Width;
            point.Y -= 0.5f * size.Height;

            if (!HorizontalAlignment.Equals(0.0))
            {
                float dx = (float)HorizontalAlignment * 0.5f * size.Width;
                point.X += dx;
            }
            if (!VerticalAlignment.Equals(0.0))
            {
                float dy = (float)VerticalAlignment * 0.5f * size.Height;
                point.Y += dy;
            }
            if (Rotation.Equals(0.0))
            {
                graphics.DrawString(Text, font, fill, point);
            }
            else
            {
                System.Drawing.Drawing2D.Matrix matrix = graphics.Transform;
                System.Drawing.Drawing2D.Matrix rot    = matrix.Clone();
                rot.RotateAt((float)Rotation, anchor);
                graphics.Transform = rot;
                graphics.DrawString(Text, font, fill, point);
                graphics.Transform = matrix;
            }

            fill.Dispose();
        }
Example #10
0
        Matrix2D trans_D2C;         //显示拓扑坐标系(原点在minx,miny处)->窗口客户区坐标系

        void UpdateMapping()        //更新映射关系
        {
            int offset_x = (ClientSize.Width - bmp.Width) / 2;
            int offset_y = (ClientSize.Height - bmp.Height) / 2;

            trans_D2C = new Matrix2D(1, 0, 0, -1, 0, display.maxy);                 //Y翻转
            trans_D2C.Scale(1 / zoom, 1 / zoom, MatrixOrder.Append);                //再缩放
            trans_D2C.Translate(offset_x, offset_y, MatrixOrder.Append);            //再平移
            trans_D2C.Translate(delta.X, delta.Y, MatrixOrder.Append);              //再平移(鼠标平移分量)

            //trans_C2D = new Matrix2D();
            //trans_C2D.Translate(-delta.X, -delta.Y, MatrixOrder.Append);	//先抵消鼠标平移分量
            //trans_C2D.Translate(-offset_x, -offset_y, MatrixOrder.Append);	//先平移回原点
            //trans_C2D.Scale(zoom, zoom, MatrixOrder.Append);				//反向缩放
            //trans_C2D.Multiply(new Matrix2D(1, 0, 0, -1, 0, display.maxy), MatrixOrder.Append);//颠倒Y坐标轴

            trans_C2D = trans_D2C.Clone();
            trans_C2D.Invert();
        }
        /// <summary>
        /// Snap rotate to some angle. Preserve scale and translation.
        /// </summary>
        /// <param name="mat"></param>
        /// <param name="angle">__ANGLE IS IN DEGREES__</param>
        /// <returns></returns>
        public static d2d.Matrix eSnapRotate(this d2d.Matrix mat, double angle)
        {
            // Graphics tries to work opposite of OpenGL, in Drawing2D:
            // PRE - multiply for local
            // post -multiply for global
            var curmat = mat.Elements;
            // get the vector components.
            var x_axis = new ai.Vector2D(curmat[0], curmat[1]);
            var y_axis = new ai.Vector2D(curmat[2], curmat[3]);
            // Get the scale of current matrix
            double x_len  = x_axis.Length();
            double y_len  = y_axis.Length();
            var    newmat = new d2d.Matrix();

            // Preserve scale and translation
            // This means: v*M = v*(S * R * T)
            newmat.Scale((float)x_len, (float)y_len);
            newmat.Rotate((float)angle);
            newmat.Translate(curmat[4], curmat[5]);
            return(newmat.Clone());
        }
Example #12
0
        void DrawActiveButtonByState(Graphics g, _States state, int x, int y)
        {
            MemoryStream ms = new MemoryStream();

            switch (state)
            {
            case _States.Normal:
                CxViewerResources.PathButton.Save(ms, ImageFormat.Png);
                break;

            case _States.MouseOver:
                CxViewerResources.PathActiveButton.Save(ms, ImageFormat.Png);
                break;

            case _States.Clicked:
                CxViewerResources.PathActiveButton.Save(ms, ImageFormat.Png);
                break;

            case _States.Selected:
                CxViewerResources.PathSelectedButton.Save(ms, ImageFormat.Png);
                break;
            }
            System.Drawing.Image image = System.Drawing.Image.FromStream(ms);

            //flip the image around its center
            using (System.Drawing.Drawing2D.Matrix m = g.Transform)
            {
                using (System.Drawing.Drawing2D.Matrix saveM = m.Clone())
                {
                    float c = (float)y;

                    using (System.Drawing.Drawing2D.Matrix m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c))
                        m.Multiply(m2);

                    //g.Transform = m;
                    g.DrawImage(image, (float)(x), (float)(y), 200, 28);
                    g.Transform = saveM;
                }
            }
        }
        /// <summary>
        /// Rescale the matrix. Preserve rotation and translation.
        /// </summary>
        /// <param name="mat"></param>
        /// <returns></returns>
        public static d2d.Matrix eSnapScale(this d2d.Matrix mat, double scale = 1.0)
        {
            var curmat = mat.Elements;
            // normalise the x and y axis to set scale to 1.0f
            var x_axis = new ai.Vector2D(curmat[0], curmat[1]);
            var y_axis = new ai.Vector2D(curmat[2], curmat[3]);

            x_axis.Normalize();
            y_axis.Normalize();
            // scale the axis
            x_axis.X *= (float)scale;
            x_axis.Y *= (float)scale;
            y_axis.X *= (float)scale;
            y_axis.Y *= (float)scale;
            // make new matrix with scale of 1.0f
            // Do not change the translation
            var newmat = new d2d.Matrix(x_axis[0], x_axis[1]
                                        , y_axis[0], y_axis[1]
                                        , curmat[4], curmat[5]
                                        );

            return(newmat.Clone());
        }
Example #14
0
    private void DrawNodes(Drawing.Graphics graphics)
    {
        Drawing2D.Matrix matrix = viewMatrix.Clone();
        int totalHeight         = 0;

        foreach (TreeNodeEx treeNode in this.nodes)
        {
            DrawNode(treeNode, graphics, matrix, ref totalHeight);
            matrix.Translate(0.0f, this.HeightIndent + this.Font.Height);
        }

        this.vScrollBar.Visible = (totalHeight > this.Height);

        if (this.vScrollBar.Visible)
        {
            this.vScrollBar.Maximum = totalHeight - this.Height + this.HeightIndent + this.Font.Height;
        }
        else
        {
            this.viewMatrix.Reset();
            this.vScrollBar.Value = 0;
        }
    }
Example #15
0
        static void DrawStringInRectCenter(Graphics g, Brush brush, Font f, string s, RectangleF r /*, double rectLineWidth*/)
        {
            if (String.IsNullOrEmpty(s))
            {
                return;
            }

            using (System.Drawing.Drawing2D.Matrix m = g.Transform) {
                using (System.Drawing.Drawing2D.Matrix saveM = m.Clone()) {
                    //rotate the label around its center
                    float c = (r.Bottom + r.Top) / 2;

                    using (System.Drawing.Drawing2D.Matrix m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c)) {
                        m.Multiply(m2);
                    }
                    g.Transform = m;
                    using (StringFormat stringFormat = StringFormat.GenericTypographic)
                    {
                        g.DrawString(s, f, brush, r.Left, r.Top, stringFormat);
                    }
                    g.Transform = saveM;
                }
            }
        }
Example #16
0
 public IMatrix Clone()
 {
     return(new MatrixHandler(control.Clone()));
 }
Example #17
0
        private static bool CustomDrawNode(Microsoft.Msagl.Drawing.Node node, object graphics, NodeTypes nodeType)
        {
            try
            {
                double width  = 110;
                double height = 40;

                Microsoft.Msagl.GeometryGraph geomGraph = new Microsoft.Msagl.GeometryGraph();
                GeomNode geomCreek = new Microsoft.Msagl.Node(node.Id, Microsoft.Msagl.Splines.CurveFactory.CreateBox(width, height, 0, 0, node.Attr.GeometryNode.Center));
                node.Attr.GeometryNode.BoundaryCurve = Microsoft.Msagl.Splines.CurveFactory.CreateBox(width, height, 0, 0,
                                                                                                      node.Attr.GeometryNode.Center);


                Graphics g = (Graphics)graphics;

                MemoryStream ms = new MemoryStream();
                switch (nodeType)
                {
                case NodeTypes.Normal:
                    CxViewerResources.NormalNode.Save(ms, ImageFormat.Png);
                    break;

                case NodeTypes.NormalSelected:
                    CxViewerResources.NormalSelected.Save(ms, ImageFormat.Png);
                    break;

                case NodeTypes.MultiRelaitions:
                    CxViewerResources.MultiRelaitions.Save(ms, ImageFormat.Png);
                    break;

                case NodeTypes.MultiRelaitionsSelected:
                    CxViewerResources.MultiRelaitionsSelected.Save(ms, ImageFormat.Png);
                    break;
                }
                System.Drawing.Image image = System.Drawing.Image.FromStream(ms);

                //flip the image around its center
                using (System.Drawing.Drawing2D.Matrix m = g.Transform)
                {
                    using (System.Drawing.Drawing2D.Matrix saveM = m.Clone())
                    {
                        float c = (float)node.Attr.GeometryNode.Center.Y;

                        using (System.Drawing.Drawing2D.Matrix m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c))
                            m.Multiply(m2);

                        g.Transform = m;

                        g.SetClip(FillTheGraphicsPath(node.Attr.GeometryNode.BoundaryCurve));


                        g.DrawImage(image, new PointF((float)(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), (float)(node.Attr.GeometryNode.Center.Y - node.Attr.GeometryNode.Height / 2)));

                        Font myFont = new System.Drawing.Font("Helvetica", 10, System.Drawing.FontStyle.Italic);
                        System.Drawing.Brush myBrush = new SolidBrush(System.Drawing.Color.Blue);

                        Rectangle    rectString   = new Rectangle(Convert.ToInt32(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), Convert.ToInt32(node.Attr.GeometryNode.Center.Y - node.Attr.GeometryNode.Height / 2), Convert.ToInt32(width), Convert.ToInt32(height));
                        StringFormat stringFormat = new StringFormat();
                        stringFormat.Alignment     = StringAlignment.Center;
                        stringFormat.LineAlignment = StringAlignment.Center;

                        g.DrawString(node.Label.Text, myFont, myBrush,
                                     rectString,
                                     stringFormat
                                     // new PointF((float)(node.Attr.GeometryNode.Center.X - node.Attr.GeometryNode.Width / 2), (float)(node.Attr.GeometryNode.Center.Y - 5))
                                     );

                        g.Transform = saveM;
                    }
                }
            }
            catch (Exception err)
            {
                Common.Logger.Create().Error(err.ToString());
            }

            return(true);//returning false would enable the default rendering
        }
Example #18
0
        protected virtual bool InitializeTransformMatrix()
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (!CheckGraphSanity()) { return false; }
            if (this.StartIndex == this.EndIndex || this.EndIndex > this.dateSerie.Length - 1)
            {
               this.IsInitialized = false;
               InvalidSerieException e = new InvalidSerieException("Invalid input data range...");
               StockLog.Write(e);
               throw e;
            }
            if (this.GraphRectangle.Height > 0)
            {
               minValue = float.MaxValue;
               maxValue = float.MinValue;
               this.CurveList.GetMinMax(StartIndex, EndIndex, ref minValue, ref maxValue, this.ScaleInvisible);

               if (minValue == maxValue || minValue == float.MaxValue || float.IsNaN(minValue) || float.IsInfinity(minValue) || maxValue == float.MinValue || float.IsNaN(maxValue) || float.IsInfinity(maxValue))
               {
                  this.Deactivate("Input data is corrupted and cannot be displayed...", false);
                  return false;
               }

               if (this.IsLogScale && minValue > 0)
               {
                  minValue *= 0.95f;
               }
               else
               {
                  minValue -= (maxValue - minValue) * 0.1f;
               }
               maxValue += (maxValue - minValue) * 0.1f;

               float tmpMinValue, tmpMaxValue;
               if (this.IsLogScale)
               {
                  tmpMinValue = minValue < 0 ? (float)-Math.Log10(-minValue + 1) : (float)Math.Log10(minValue + 1);
                  tmpMaxValue = maxValue < 0 ? (float)-Math.Log10(-maxValue + 1) : (float)Math.Log10(maxValue + 1);
               }
               else
               {
                  tmpMinValue = minValue;
                  tmpMaxValue = maxValue;
               }

               float coefX = (this.GraphRectangle.Width * 0.96f) / (EndIndex - StartIndex);
               float coefY = this.GraphRectangle.Height / (tmpMaxValue - tmpMinValue);

               matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
               matrixValueToScreen.Translate(this.GraphRectangle.X - (StartIndex - 0.5f) * coefX, tmpMaxValue * coefY + this.GraphRectangle.Y);
               matrixValueToScreen.Scale(coefX, -coefY);

               matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
               matrixScreenToValue.Invert();
            }
            else
            {
               this.Deactivate("App too small...", false);
               return false;
            }
            return true;
             }
        }