欢迎光临散文网 会员登陆 & 注册

浮云绘图CAD绘图编辑器之直线、方块、圆等基础图元操作和接口源码

2022-06-10 15:09 作者:浮云绘图  | 我要投稿

浮云绘图是一整套绘图软件sdk(绘图编辑器+绘图组件DLL+API Demo+说明文档),可以快速开发各类状态度、电子图图纸、流程图、平面布局图等。其中基础绘图单元就有直线、矩形方块、椭圆(含圆),本文详细介绍此3类基础图元的详细使用操作,和sdk二次开发中接口函数及使用实例(如有特殊需求,小功能微改免费,更多变动支持驻场开发)。


先看看浮云绘图的几个示例如下所示,支持动态控制各线条、区域、文字、图片的颜色、虚实、大小、状态等属性。

浮云绘图示例:车站设备状态图
浮云绘图示例:车站设备状态图


浮云绘图示例:工控采集设备状态图
浮云绘图示例:工控采集设备状态图


浮云绘图示例:电路原理图



1. 浮云绘图开源软件之直线

直线,是所有绘图软件的最基础图形,直线可以做连线、电路线路、关系线、分割线,还可以拼接成各类图形,比如三角形、五角形等等。

线条的属性,包括线的宽度、颜色、虚实(含隐藏)、端点模式。

1.1 直线的画法

画直线操作:点击工具栏直线图标按钮 -> 在绘图区按下鼠标左键 -> 移动鼠标(实时画线) -> 松开鼠标(完成一条直线),再根据需要,(双击该直线,弹出属性对话框)设置线条的宽度、颜色、虚实、端点模式等属性值。

浮云绘图之线段的画法
浮云编辑器画直线


浮云绘图编辑器线条的属性设置对话框


说明:1>画直线过程是先确定左上点,然后鼠标移动过程中是右下点(左上点+右上点确定一个矩形),然后矩形的左上点与右下点连线。当起点的左上的上y值大于右下的下的y值时,直线高度是负值。2>关于旋转和角度。直线的底层实际是矩形,矩形旋转是取其4个角上点,回到xy坐标轴,成另一个矩形(如下图所示),矩形在不断旋转中,会不断趋近与正方形,而正方形旋转,两定点连线的角度不会变,变的只有长度。即直线旋转只有小于某角度才正常。

矩形旋转后变形示意


 解决办法是用浮云绘图的四角形图元,基于四个点旋转,而不是基于矩形旋转,从而旋转任意角度而不变形。

1.2 直线API接口定义及使用实例

以C#版API Demo为例(完整浮云绘图SDK开发及源码下载地址)https://download.csdn.net/download/fyhhack/85528048?spm=1001.2014.3001.5503


直线相关的接口定义如下:


        [DllImport("FYEDC.dll", EntryPoint = "SetLineColor", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetLineColor(IntPtr canvas, IntPtr shape, int color);

        [DllImport("FYEDC.dll", EntryPoint = "GetLineColor", CallingConvention = CallingConvention.Cdecl)]

        public static extern int GetLineColor(IntPtr shape);


        [DllImport("FYEDC.dll", EntryPoint = "SetLineStyle", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetLineStyle(IntPtr canvas, IntPtr shape, int style);

        [DllImport("FYEDC.dll", EntryPoint = "GetLineStyle", CallingConvention = CallingConvention.Cdecl)]

        public static extern int GetLineStyle(IntPtr shape);


        [DllImport("FYEDC.dll", EntryPoint = "SetLineWidth", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetLineWidth(IntPtr canvas, IntPtr shape, int width);

        [DllImport("FYEDC.dll", EntryPoint = "GetLineWidth", CallingConvention = CallingConvention.Cdecl)]

        public static extern int GetLineWidth(IntPtr shape);


        [DllImport("FYEDC.dll", EntryPoint = "SetLineEndMode", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetLineEndMode(IntPtr canvas, IntPtr shape, int mode);

        [DllImport("FYEDC.dll", EntryPoint = "GetLineEndMode", CallingConvention = CallingConvention.Cdecl)]

        public static extern int GetLineEndMode(IntPtr shape);

直线相关的接口函数使用实例如下所示:

        private void btnLine_Click(object sender, EventArgs e)

        {

            IntPtr shape = GetShapeAt(m_shapeCanvas, m_shapeSeqNum);    //获得图元对象

            if (shape != IntPtr.Zero)

            {

                // 获取数据

                LinePropForm frm = new LinePropForm();

                frm.m_iSeqNum = m_shapeSeqNum;

                frm.m_iLineColor = GetLineColor(shape);

                frm.m_iLineWidth = GetLineWidth(shape);

                frm.m_iLineStyle = GetLineStyle(shape);

                frm.m_iEndMode = GetLineEndMode(shape);


                // 设置数据

                if (DialogResult.OK == frm.ShowDialog())

                {

                    m_shapeSeqNum = frm.m_iSeqNum;      // 可以修改默认的图元序号

                    if (GetShapeCount(m_shapeCanvas) - 1 < m_shapeSeqNum)

                        m_shapeSeqNum = GetShapeCount(m_shapeCanvas) - 1;

                    if (m_shapeSeqNum < 0)

                        m_shapeSeqNum = 0;


                    IntPtr shape2 = GetShapeAt(m_shapeCanvas, m_shapeSeqNum);

                    if (shape2 != IntPtr.Zero)

                    {

                        SetLineColor(m_shapeCanvas, shape2, frm.m_iLineColor);

                        SetLineWidth(m_shapeCanvas, shape2, frm.m_iLineWidth);

                        SetLineStyle(m_shapeCanvas, shape2, frm.m_iLineStyle);

                        SetLineEndMode(m_shapeCanvas, shape2, frm.m_iEndMode);

                    }

                }

            }

        }


2. 浮云绘图开源软件之方块(矩形)

矩形方块,是浮云绘图第2基础图元,方块可以画矩形、画正方形,一般应用于框、区域块、设备盒子等逻辑对象。

矩形方块属性包括线条、区域、文字三个方面。

线条:线宽、颜色、虚实;

区域:是否填充区域、填充颜色;

文字:文字内容、文字是否显示、字体颜色、字体类型、字体大小。

2.1 矩形方块的画法

矩形画法:点击左侧工具栏矩形图标按钮  -> 在绘图区按下鼠标左键 -> 移动鼠标(实时画矩形) -> 松开鼠标(完成画矩形),再根据需要,(双击该矩形,弹出属性对话框)设置矩形线条(宽度、颜色、虚实)、区域(是否填充、填充颜色)、文字(内容、字体颜色、字号等)属性值。

浮云绘图之矩形方块画法
浮云绘图之矩形方块画法


 上图为了更容易看清区域是否填充,绘图背景使用了灰底+网格线。

浮云绘图之矩形方块属性设置对话框
浮云绘图之矩形方块属性设置对话框


2.2 矩形API接口定义及使用实例

以C#版API Demo为例(完整浮云绘图SDK开发及源码下载地址

矩形图元相关的接口定义如下(矩形的线条属性设置接口与上节直线接口一致):

       [DllImport("FYEDC.dll", EntryPoint = "SetFillColor", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetFillColor(IntPtr canvas, IntPtr shape, int color);

        [DllImport("FYEDC.dll", EntryPoint = "GetFillColor", CallingConvention = CallingConvention.Cdecl)]

        public static extern int GetFillColor(IntPtr shape);


        [DllImport("FYEDC.dll", EntryPoint = "SetIsFill", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetIsFill(IntPtr canvas, IntPtr shape, int isFill);

        [DllImport("FYEDC.dll", EntryPoint = "GetIsFill", CallingConvention = CallingConvention.Cdecl)]

        public static extern int GetIsFill(IntPtr shape);


        [DllImport("FYEDC.dll", EntryPoint = "SetFontColor", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetFontColor(IntPtr canvas, IntPtr shape, int color);

        [DllImport("FYEDC.dll", EntryPoint = "GetFontColor", CallingConvention = CallingConvention.Cdecl)]

        public static extern int GetFontColor(IntPtr shape);

        [DllImport("FYEDC.dll", EntryPoint = "SetFontType", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetFontType(IntPtr canvas, IntPtr shape, string type);

        [DllImport("FYEDC.dll", EntryPoint = "GetFontType", CallingConvention = CallingConvention.Cdecl)]

        public static extern void GetFontType(IntPtr shape, ref byte type);

        [DllImport("FYEDC.dll", EntryPoint = "SetFontSize", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetFontSize(IntPtr canvas, IntPtr shape, int size);

        [DllImport("FYEDC.dll", EntryPoint = "GetFontSize", CallingConvention = CallingConvention.Cdecl)]

        public static extern int GetFontSize(IntPtr shape);


        [DllImport("FYEDC.dll", EntryPoint = "SetShapeText", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetShapeText(IntPtr canvas, IntPtr shape, string text);

        [DllImport("FYEDC.dll", EntryPoint = "GetShapeText", CallingConvention = CallingConvention.Cdecl)]

        public static extern void GetShapeText(IntPtr shape, ref byte text);

        [DllImport("FYEDC.dll", EntryPoint = "SetTextVisible", CallingConvention = CallingConvention.Cdecl)]

        public static extern void SetTextVisible(IntPtr canvas, IntPtr shape, int isShow);

        [DllImport("FYEDC.dll", EntryPoint = "GetTextVisible", CallingConvention = CallingConvention.Cdecl)]

        public static extern int GetTextVisible(IntPtr shape);

浮云绘图DLL组件的矩形接口API使用实例如下所示:

        private void btnArea_Click(object sender, EventArgs e)

        {

            IntPtr shape = GetShapeAt(m_shapeCanvas, m_shapeSeqNum);    //获得图元对象

            if (shape != IntPtr.Zero)

            {

                // 获取数据

                AreaPropForm frm = new AreaPropForm();

                frm.m_iSeqNum = m_shapeSeqNum;

                frm.m_iFillColor = GetFillColor(shape);

                frm.m_isFill = GetIsFill(shape);


                // 设置数据

                if (DialogResult.OK == frm.ShowDialog())

                {

                    m_shapeSeqNum = frm.m_iSeqNum;      // 可以修改默认的图元序号

                    if (GetShapeCount(m_shapeCanvas) - 1 < m_shapeSeqNum)

                        m_shapeSeqNum = GetShapeCount(m_shapeCanvas) - 1;

                    if (m_shapeSeqNum < 0)

                        m_shapeSeqNum = 0;


                    IntPtr shape2 = GetShapeAt(m_shapeCanvas, m_shapeSeqNum);

                    if (shape2 != IntPtr.Zero)

                    {

                        SetFillColor(m_shapeCanvas, shape2, frm.m_iFillColor);

                        SetIsFill(m_shapeCanvas, shape2, frm.m_isFill);

                    }

                }

            }

        }



        private void btnText_Click(object sender, EventArgs e)

        {

            IntPtr shape = GetShapeAt(m_shapeCanvas, m_shapeSeqNum);    //获得图元对象

            if (shape != IntPtr.Zero)

            {

                // 获取数据

                TextPropForm frm = new TextPropForm();

                frm.m_iSeqNum = m_shapeSeqNum;


                byte[] bys = new byte[200];

                lock (bys)

                {

                    GetShapeText(shape, ref bys[0]);     //获取图元Title

                }

                String sTxt = ByteToString(bys);


                frm.m_sContent = sTxt;

                frm.m_isDisplay = GetTextVisible(shape);


                // 设置数据

                if (DialogResult.OK == frm.ShowDialog())

                {

                    m_shapeSeqNum = frm.m_iSeqNum;      // 可以修改默认的图元序号

                    if (GetShapeCount(m_shapeCanvas) - 1 < m_shapeSeqNum)

                        m_shapeSeqNum = GetShapeCount(m_shapeCanvas) - 1;

                    if (m_shapeSeqNum < 0)

                        m_shapeSeqNum = 0;


                    IntPtr shape2 = GetShapeAt(m_shapeCanvas, m_shapeSeqNum);

                    if (shape2 != IntPtr.Zero)

                    {

                        SetShapeText(m_shapeCanvas, shape2, frm.m_sContent);

                        SetTextVisible(m_shapeCanvas, shape2, frm.m_isDisplay);

                    }

                }

            }

        }



        private void btnFont_Click(object sender, EventArgs e)

        {

            IntPtr shape = GetShapeAt(m_shapeCanvas, m_shapeSeqNum);    //获得图元对象

            if (shape != IntPtr.Zero)

            {

                // 获取数据

                FontPropForm frm = new FontPropForm();

                frm.m_iSeqNum = m_shapeSeqNum;               

                frm.m_iFontColor = GetFontColor(shape);

                frm.m_iFontSize = GetFontSize(shape);


                byte[] bys = new byte[200];

                lock (bys)

                {

                    GetFontType(shape, ref bys[0]);     

                }

                String sTxt = ByteToString(bys);

                frm.m_sFontStyle = sTxt;


                // 设置数据

                if (DialogResult.OK == frm.ShowDialog())

                {

                    m_shapeSeqNum = frm.m_iSeqNum;      // 可以修改默认的图元序号

                    if (GetShapeCount(m_shapeCanvas) - 1 < m_shapeSeqNum)

                        m_shapeSeqNum = GetShapeCount(m_shapeCanvas) - 1;

                    if (m_shapeSeqNum < 0)

                        m_shapeSeqNum = 0;


                    IntPtr shape2 = GetShapeAt(m_shapeCanvas, m_shapeSeqNum);

                    if (shape2 != IntPtr.Zero)

                    {

                        SetFontType(m_shapeCanvas, shape2, frm.m_sFontStyle);

                        SetFontColor(m_shapeCanvas, shape2, frm.m_iFontColor);

                        SetFontSize(m_shapeCanvas, shape2, frm.m_iFontSize);

                    }

                }

            }

        }


3. 浮云绘图开源软件之椭圆(圆)

椭圆,是浮云绘图第3基础图元,椭圆可以画各种椭圆、画正圆,一般应用于区域、信号灯、球体等逻辑对象。

椭圆属性与矩形方块一致,包括线条、区域、文字三个方面。

线条:线宽、颜色、虚实;

区域:是否填充区域、填充颜色;

文字:文字内容、文字是否显示、字体颜色、字体类型、字体大小。

3.1 椭圆的画法

参考画矩形操作。

浮云绘图开源软件之椭圆
 浮云绘图开源软件之椭圆


3.2 椭圆API接口定义及使用实例

参考矩形接口使用。

浮云绘图基础图元还包括三角形、四角形、多点线、扇形、文字、图片等。具体操作和API示例请参考后面章节。如需定制更多基础图元(小改免费),甚至驻场定制开发都可以。

浮云绘图CAD绘图编辑器之直线、方块、圆等基础图元操作和接口源码的评论 (共 条)

分享到微博请遵守国家法律