关于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.

相关推荐
qystca6 分钟前
洛谷 B3637 最长上升子序列 C语言 记忆化搜索->‘正序‘dp
c语言·开发语言·算法
薯条不要番茄酱6 分钟前
数据结构-8.Java. 七大排序算法(中篇)
java·开发语言·数据结构·后端·算法·排序算法·intellij-idea
今天吃饺子11 分钟前
2024年SCI一区最新改进优化算法——四参数自适应生长优化器,MATLAB代码免费获取...
开发语言·算法·matlab
努力进修15 分钟前
“探索Java List的无限可能:从基础到高级应用“
java·开发语言·list
Ajiang28247353042 小时前
对于C++中stack和queue的认识以及priority_queue的模拟实现
开发语言·c++
幽兰的天空2 小时前
Python 中的模式匹配:深入了解 match 语句
开发语言·python
Theodore_10225 小时前
4 设计模式原则之接口隔离原则
java·开发语言·设计模式·java-ee·接口隔离原则·javaee
----云烟----7 小时前
QT中QString类的各种使用
开发语言·qt
lsx2024067 小时前
SQL SELECT 语句:基础与进阶应用
开发语言
开心工作室_kaic8 小时前
ssm161基于web的资源共享平台的共享与开发+jsp(论文+源码)_kaic
java·开发语言·前端