关于DrawTools的分析- 一个优秀的C#开源绘图软件

国外大佬,曾经写过两个关于DrawTools相关的开源绘图软件。

我更新了一个优化的版本如下图,稍后会发布更新给大家。 需要的用户可发邮件给我 448283544@qq.com

应用于AGV地图编辑器如下:

那么这个优于很多普通的画布软件,包含点、多种线、矩形、椭圆基本图像,贝塞尔曲线。缩放,Redo,undo等等,那么也能自定义图像和自定义可以拖拽到画布的新的业务实体。

后面我将添加标尺和图像之间吸附, 功能将变得更加强大,与我们使用到的AutoCad类似!

应用于地图编辑器如下, 类似openTCS的C#实现:

Mark Miller

DrawTools 2014

Arnault Bonafos, 16 Jan 2014

Architecture

Dynamic handling for showing scroll bars

A dirty boolean is handled in GraphicsList, the canvas document, where it should be. To this Dirty property is associated a DocumentDirtyObserver interface.

Hide Copy Code

复制代码
public interface DocumentDirtyObserver
{
    void IsDirty(GraphicsList gList);
}

Every time the document is modified, look with the different draw tools, its Dirty property is set to true and any DocumentDirtyObserver is fired.

Hide Copy Code

复制代码
public bool Dirty
{
    get
    {
        return this.dirty;
    }
    set { this.dirty = value; if (this.dirty) { NotifyDirty(); } } } 

The class DrawArea implements the DocumentDirtyObserver, and every time the document is 'dirty', it calls AdjustRendering, which in turn computes the bounding box of the canvas document (GraphicsList).

Hide Copy Code

复制代码
void AdjustRendering()
{
    Size docSize;

    if (this.GraphicsList != null)
    {
        docSize = this.GraphicsList.GetSize();
        docSize.Width += 20; docSize.Height += 20; AutoScrollMinSize = docSize; } else { AutoScrollMinSize = new Size(0, 0); } Invalidate(); } 

This way, it implements the Mode/View/Controller design pattern, the GraphicsList being the model, DrawArea being the View and the draw Tools being the controller.

In the future, Dirty property should be handled in only one place (it is also handled in the DrawArea class).

Export the graph to JPEG format

The DrawTools 2014 architecture is good enough to be followed to implement a new menu strip option.

  1. Add a menu item to the menu bar

    Simply open the MainForm designer and add the option

  2. Link the MenuItem to a MainForm method to trigger the CommandExportToJpg

    Hide Copy Code

    复制代码
    private void CommandExportToJpg()
    {
        docManager.ExportToJpg();
    }
  3. Implement the user interface logic in the DocManager ExportToJpg

    I let you look at the DocManager.ExportToJpg

  4. Subscribe MainForm ExportEvent method implementation to DocManager event.

Hide Copy Code

复制代码
docManager.ExportEvent += docManager_ExportEvent;
  1. Implement MainForm logic to actually transform image bitmap into JPEG file.

    All is in the source code, I don't copy it here as it is essentially technical stuff.

相关推荐
辞忧九千七3 分钟前
吃透Redis7核心数据结构:从基础用法到实战场景(Python版)
开发语言·数据结构·redis·python
魔法阵维护师5 分钟前
从零开发游戏需要学习的c#模块,第二十七章(远程攻击 —— 发射子弹)
学习·游戏·c#
空圆小生5 分钟前
基于 Python+Vue3 的 AI 人脸识别门禁考勤系统
开发语言·人工智能·python
weixin_4280053011 分钟前
C#调用 AI学习从0开始-第1阶段(基础与工具)-第7天多轮对话记忆
人工智能·学习·c#·多轮对话·千问api调用
搬砖的小码农_Sky15 分钟前
macOS Sequoia上如何安装Python开发环境?
开发语言·python·macos
人间乄惊鸿客18 分钟前
c++自记录
java·开发语言·c++
csbysj202020 分钟前
MySQL 删除数据表
开发语言
wjs202420 分钟前
R 语言中的数组(Array)
开发语言
蓝影灵20 分钟前
单体改微服务记录
java·开发语言
李少兄22 分钟前
Java 短路求值的优雅实践:用 `&&` 实现安全高效的批量操作控制
java·开发语言