/// <summary> /// constructor /// </summary> /// <param name="profile">ProfileWall or ProfileFloor</param> public NewOpeningsForm(Profile profile) : this() { m_profile = profile; m_to2DMatrix = m_profile.To2DMatrix(); m_moveToCenterMatrix = m_profile.ToCenterMatrix(); InitTools(); }
/// <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; }
/// <summary> /// Get a matrix which can transform points to 2D /// </summary> public Matrix4 To2DMatrix() { if(m_dataProfile is Wall) { return WallMatrix(); } List<XYZ> eg0 = m_face[0].Tessellate() as List<XYZ>; List<XYZ> eg1 = m_face[1].Tessellate() as List<XYZ>; Vector4 v1 = new Vector4((float)eg0[0].X, (float)eg0[0].Y, (float)eg0[0].Z); Vector4 v2 = new Vector4((float)eg0[1].X, (float)eg0[1].Y, (float)eg0[1].Z); Vector4 v21 = v1 - v2; v21.Normalize(); Vector4 v3 = new Vector4((float)eg1[0].X, (float)eg1[0].Y, (float)eg1[0].Z); Vector4 v4 = new Vector4((float)eg1[1].X, (float)eg1[1].Y, (float)eg1[1].Z); Vector4 v43 = v4 - v3; v43.Normalize(); Vector4 vZAxis = Vector4.CrossProduct(v43, v21); Vector4 vYAxis = Vector4.CrossProduct(vZAxis, v43); vYAxis.Normalize(); vZAxis.Normalize(); Vector4 vOrigin = (v4 + v1) / 2; Matrix4 result = new Matrix4(v43, vYAxis, vZAxis, vOrigin); return result; }
private void openingPictureBox_Paint(object sender, PaintEventArgs e) { //Draw the pictures in the m_tools list foreach (ITool tool in m_tools) { tool.Draw(e.Graphics); } //draw the tips string e.Graphics.DrawString(m_tool.ToolType.ToString(), SystemFonts.DefaultFont, SystemBrushes.Highlight, 2, 5); //move the origin to the picture center Size size = this.openingPictureBox.Size; e.Graphics.Transform = new System.Drawing.Drawing2D.Matrix( 1, 0, 0, 1, size.Width / 2, size.Height / 2); //draw profile Size scaleSize = new Size((int)(0.85 * size.Width), (int)(0.85 * size.Height)); m_scaleMatrix = ComputerScaleMatrix(scaleSize); Matrix4 trans = Comuter3DTo2DMatrix(); m_profile.Draw2D(e.Graphics, Pens.Blue, trans); }
/// <summary> /// Draw profile of wall or floor in 2D /// </summary> /// <param name="graphics">form graphic</param> /// <param name="pen">pen use to draw line in pictureBox</param> /// <param name="matrix4">matrix used to transform points between 3d and 2d.</param>> public void Draw2D(Graphics graphics, Pen pen, Matrix4 matrix4) { foreach (Edge edge in m_face) { List<XYZ> points = edge.Tessellate() as List<XYZ>; for (int i = 0; i < points.Count - 1; i++) { Autodesk.Revit.DB.XYZ point1 = points[i]; Autodesk.Revit.DB.XYZ point2 = points[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)); } } }