使用NetronGraphLib類庫開發Qfd質量屋編制工具


前言

可執行文件下載  QfdHouse-exe.zip  

因項目需要做了一個質量功能配置(Quality Function Deployment 簡稱Qfd)的質量屋編制工具軟件,本軟件是在發布一個免費開源軟件-- PAD流程圖繪制軟件PADFlowChart基礎之上做的,效果如下:

 支持新建、保存、導出圖片,自定義用戶需求和技術特性,單元格點擊切換關聯矩陣程度和自關聯矩陣的相關性。

開發中解決的問題

相信來這的人對Qfd是不感興趣的,下面就把遇到的問題說一下。

如何設置圖形的初始大小

1.在Shape類增加默認高度和寬度的屬性

       /// <summary>
        /// 默認寬度
        /// </summary>
        private float mDefaultWidth = 0f;

        /// <summary>
        /// 默認高度
        /// </summary>
        private float mDefaultHeigh = 0f;
  /// <summary>
        /// 默認寬度
        /// </summary>
        [GraphMLData]public float DefaultWidth
        {
            get { return mDefaultWidth; }
            set { mDefaultWidth = value; }
        }
        /// <summary>
        /// 默認高度
        /// </summary>
        [GraphMLData]
        public float DefaultHeigh
        {
            get { return mDefaultHeigh; }
            set { mDefaultHeigh = value; }
        }

2.在TableShape類中初始化

        public TableShape() : base()
        {
            this.Init();
            this.InitTestData3();
            BindingEventHandler();
            base.DefaultWidth = 300;
            base.DefaultHeigh = 100;
        }

3.修改GraphControl的DrawShapeMouseUp(PointF p)函數

   private void DrawShapeMouseUp(PointF p)
        {
            Cursor = System.Windows.Forms.Cursors.Default;


            float t_left = (mMouseDownPoint.X < p.X ? mMouseDownPoint.X : p.X);
            float t_right = (mMouseDownPoint.X >= p.X ? mMouseDownPoint.X : p.X);
            float t_top = (mMouseDownPoint.Y < p.Y ? mMouseDownPoint.Y : p.Y);
            float t_bottom = (mMouseDownPoint.Y >= p.Y ? mMouseDownPoint.Y : p.Y);

            if (t_right - t_left < 10)
            {
               // t_right = t_left + mDefaultShapeWidth;
                t_right = t_left + Math.Max(mDefaultShapeWidth, mshapeObject.DefaultWidth);
            }

            if (t_bottom - t_top < 10)
            {
                //t_bottom = t_top + mDefaultShapeHeight;
                t_bottom = t_top + Math.Max(mDefaultShapeHeight, mshapeObject.DefaultHeigh);          
            }
            mshapeObject.Rectangle = RectangleF.FromLTRB(t_left, t_top, t_right, t_bottom);

            Invalidate();

            EndDrawShapeWithMouse();
        }

注釋掉的是原來的代碼

如何導出圖形到圖片格式

1. 在FlowChartForm.cs中增加保存圖形圖片的方法

  public bool SaveShapeImage()
        {
            if (graphControl.SelectedShapes.Count != 1)
            {
                MessageBox.Show("請選中一個圖形");
                return false;
            }

            var fileName = string.Empty;
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.DefaultExt = ".jpg";
                sfd.Filter = "jpg file(*.jpg)|*.jpg";


                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    fileName = sfd.FileName;
                }
                else
                {
                    return false;
                }
            }
            var shape = graphControl.SelectedShapes[0];
            graphControl.SaveShapeImage(fileName, shape);
            return true;
        }

2.在GraphControl.cs中增加SaveShapeImage方法

  public void SaveShapeImage(string path,Shape shape)
        {
            Image bmp = GetShapeImage(shape);
            bmp.Save(path);
        }

        public Image GetShapeImage(Shape  shape)
        {
            var oldRectangle = shape.Rectangle;
            var newRectangle = new RectangleF(0, 0, oldRectangle.Width, oldRectangle.Height);
            shape.Rectangle = newRectangle;
            Bitmap bmp = new Bitmap((int)shape.Rectangle.Width, (int)shape.Rectangle.Height, this.CreateGraphics());
   
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                shape.Paint(g);             
            }
            shape.Rectangle = oldRectangle;
         Image.GetThumbnailImageAbort tCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
            return bmp.GetThumbnailImage((int)shape.Rectangle.Width,(int)shape.Rectangle.Height, tCallback, IntPtr.Zero);
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM