首页 > 代码库 > 使用NetronGraphLib类库开发Qfd质量屋编制工具

使用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);        }

 

使用NetronGraphLib类库开发Qfd质量屋编制工具