/// <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); }
///------------------------------------------------------------------------------------------------- /// \fn private void MainView_MouseMove(object sender, MouseEventArgs e) /// /// \brief Event handler. Called by MainView for mouse move events /// /// \param sender Source of the event. /// \param e Mouse event information. ///------------------------------------------------------------------------------------------------- private void MainView_MouseMove(object sender, MouseEventArgs e) { if (isEnabled) { mainView.Image.Dispose(); mainView.Image = (Image)doubleBuffer.Clone(); using (Graphics g = Graphics.FromImage(mainView.Image)) { LineTool linetool = (LineTool)ToolKit.GetInstance().lineTool; linetool.Draw(g, Setting.GetInstance().Pen, arrayList[arrayList.Count - 1], e.Location); } } }
///------------------------------------------------------------------------------------------------- /// \fn private void MainView_MouseClick(object sender, MouseEventArgs e) /// /// \brief Event handler. Called by MainView for mouse click events /// /// \param sender Source of the event. /// \param e Mouse event information. ///------------------------------------------------------------------------------------------------- private void MainView_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (arrayList.Count == 0) { doubleBuffer = (Image)mainView.Image.Clone(); arrayList.Add(e.Location); this.isEnabled = true; return; } doubleBuffer = (Image)mainView.Image.Clone(); arrayList.Add(e.Location); using (Graphics g = Graphics.FromImage(mainView.Image)) { // g.DrawLine(Setting.GetInstance().Pen, (Point)arrayList[arrayList.Count - 2], e.Location); LineTool lineTool = (LineTool)ToolKit.GetInstance().lineTool; lineTool.Draw(g, Setting.GetInstance().Pen, arrayList[arrayList.Count - 2], e.Location); } } else { this.isEnabled = false; mainView.Image = (Image)doubleBuffer.Clone(); //save into actions array. Polygon polygon = new Polygon(); polygon.pen = Setting.GetInstance().Pen.Clone() as Pen; polygon.pointArray = new List <Point>(arrayList.ToArray()); Log.LogText(String.Format("Create Polygon")); History.GetInstance().PushBackAction( new MAction(this, polygon)); MakeAction(polygon); //some termination arrayList.Clear(); } }
///------------------------------------------------------------------------------------------------- /// \fn public override void MakeAction(ActionParameters_t toolParameters) /// /// \brief Makes an action /// /// \exception InvalidCastException Thrown when an object cannot be cast to a required type. /// /// \param toolParameters Options for controlling the tool. ///------------------------------------------------------------------------------------------------- public override void MakeAction(ActionParameters_t toolParameters) { try { Polygon polygon = (Polygon)toolParameters; using (Graphics g = Graphics.FromImage(mainView.Image)) { LineTool lineTool = (LineTool)ToolKit.GetInstance().lineTool; int length = polygon.pointArray.Count; for (int i = 0; i < length; i++) { lineTool.Draw(g, polygon.pen, polygon.pointArray[i % length], polygon.pointArray[(i + 1) % length]); } if (polygon.backColor != Color.White) { g.FillPolygon(new SolidBrush(polygon.backColor), polygon.pointArray.ToArray()); } } } catch (InvalidCastException) { throw; } }