Matrix used to transform between ucs coordinate and world coordinate.
Example #1
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="profile">ProfileWall or ProfileFloor</param>
 public NewPathReinforcementForm(Profile profile)
     : this()
 {
     m_profile = profile;
     m_to2DMatrix = m_profile.To2DMatrix;
     m_moveToCenterMatrix = m_profile.ToCenterMatrix();
     m_tool = new LineTool();
     this.KeyPreview = true; //respond Form events first
     m_pointsPreview = new List<List<XYZ>>();
     m_sizePictureBox = this.pictureBox.Size;
 }
Example #2
0
        /// <summary>
        /// Get a matrix which can transform points to 2D
        /// </summary>
        /// <returns>matrix which can transform points to 2D</returns>
        public override Matrix4 GetTo2DMatrix()
        {
            View viewLevel2 = null;

            // select the view which is named "Level 2"
            // Once use the View type to filterrrr the element ,please skip the view templates
            // because they're behind-the-scene and invisible in project browser; also invalid for API.
            IEnumerable<View> views = from elem in
                                                  (new FilteredElementCollector(m_commandData.Application.ActiveUIDocument.Document)).OfClass(typeof(ViewPlan)).ToElements()
                                              let view = elem as View
                                              where (view != null) && (!view.IsTemplate) && (view.ViewName == "Level 2")
                                              select view;
            viewLevel2 = views.First();

            Vector4 xAxis = new Vector4(viewLevel2.RightDirection);
            //Because Y axis in windows UI is downward, so we should Multiply(-1) here
            Vector4 yAxis = new Vector4(viewLevel2.UpDirection.Multiply(-1));
            Vector4 zAxis = new Vector4(viewLevel2.ViewDirection);

            Matrix4 result = new Matrix4(xAxis, yAxis, zAxis);
            return result;
        }
Example #3
0
        /// <summary>
        /// draw profile of wall or floor in 2D
        /// </summary>
        /// <param name="graphics">form graphic</param>
        /// <param name="pen">pen used to draw line in pictureBox</param>
        /// <param name="matrix4">Matrix used to transform 3d to 2d 
        /// and make picture in right scale </param>
        public void Draw2D(Graphics graphics, Pen pen, Matrix4 matrix4)
        {
            for (int i = 0; i < m_points.Count; i++)
            {
                List<XYZ> points = m_points[i];
                for (int j = 0; j < points.Count - 1; j++)
                {
                    Autodesk.Revit.DB.XYZ point1 = points[j];
                    Autodesk.Revit.DB.XYZ point2 = points[j + 1];

                    Vector4 v1 = new Vector4(point1);
                    Vector4 v2 = new Vector4(point2);

                    v1 = matrix4.Transform(v1);
                    v2 = matrix4.Transform(v2);
                    graphics.DrawLine(pen, new Point((int)v1.X, (int)v1.Y),
                        new Point((int)v2.X, (int)v2.Y));
                }
            }
        }
Example #4
0
 /// <summary>
 ///  multiply matrix left and right
 /// </summary>
 /// <param name="left">left matrix</param>
 /// <param name="right">right matrix</param>
 /// <returns></returns>
 public static Matrix4 Multiply(Matrix4 left, Matrix4 right)
 {
     Matrix4 result = new Matrix4();
     for (int i = 0; i < 4; i++)
     {
         for (int j = 0; j < 4; j++)
         {
             result[i, j] = left[i, 0] * right[0, j] + left[i, 1] * right[1, j]
                 + left[i, 2] * right[2, j] + left[i, 3] * right[3, j];
         }
     }
     return result;
 }
Example #5
0
        /// <summary>
        /// draw the curve of slab (or wall) and path of PathReinforcement
        /// </summary>
        /// <param name="sender">object who sent this event</param>
        /// <param name="e">event args</param>
        private void PictureBox_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            if (m_previewMode)
            {
                //Draw the geometry of Path Reinforcement
                DrawPreview(e.Graphics);
                //move the gdi origin to the picture center
                e.Graphics.Transform = new
                    System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0);
                m_tool.Draw(e.Graphics);
            }
            else
            {
                //Draw the pictures in the m_tools list
                m_tool.Draw(e.Graphics);
            }

            //move the gdi origin to the picture center
            e.Graphics.Transform = new System.Drawing.Drawing2D.Matrix(
                1, 0, 0, 1, m_sizePictureBox.Width / 2, m_sizePictureBox.Height / 2);

            //get matrix
            Size scaleSize = new Size((int)(0.85 * m_sizePictureBox.Width),
                (int)(0.85 * m_sizePictureBox.Height));
            m_scaleMatrix = ComputeScaleMatrix(scaleSize);
            m_transMatrix = Compute3DTo2DMatrix();

            //draw profile
            m_profile.Draw2D(e.Graphics, Pens.Blue, m_transMatrix);
        }
Example #6
0
        /// <summary>
        /// draw points in the List on the form
        /// </summary>
        /// <param name="graphics">form graphic</param>
        /// <param name="pen">pen used to draw line in pictureBox</param>
        /// <param name="matrix4">Matrix used to transform 3d to 2d 
        /// and make picture in right scale </param>
        /// <param name="points">points need to be drawn</param>
        private void DrawPoints(Graphics graphics, Pen pen, Matrix4 matrix4, List<List<XYZ>> points)
        {
            foreach (List<XYZ> xyzArray in points)
            {
                for (int i = 0; i < xyzArray.Count - 1; i++)
                {
                    Autodesk.Revit.DB.XYZ point1 = xyzArray[i];
                    Autodesk.Revit.DB.XYZ point2 = xyzArray[i + 1];

                    Vector4 v1 = new Vector4(point1);
                    Vector4 v2 = new Vector4(point2);

                    v1 = matrix4.Transform(v1);
                    v2 = matrix4.Transform(v2);
                    graphics.DrawLine(pen, new Point((int)v1.X, (int)v1.Y),
                        new Point((int)v2.X, (int)v2.Y));
                }
            }
        }