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

相关推荐
秃头佛爷27 分钟前
Python学习大纲总结及注意事项
开发语言·python·学习
待磨的钝刨28 分钟前
【格式化查看JSON文件】coco的json文件内容都在一行如何按照json格式查看
开发语言·javascript·json
△曉風殘月〆2 小时前
WPF MVVM入门系列教程(二、依赖属性)
c#·wpf·mvvm
XiaoLeisj2 小时前
【JavaEE初阶 — 多线程】单例模式 & 指令重排序问题
java·开发语言·java-ee
励志成为嵌入式工程师3 小时前
c语言简单编程练习9
c语言·开发语言·算法·vim
逐·風3 小时前
unity关于自定义渲染、内存管理、性能调优、复杂物理模拟、并行计算以及插件开发
前端·unity·c#
捕鲸叉4 小时前
创建线程时传递参数给线程
开发语言·c++·算法
A charmer4 小时前
【C++】vector 类深度解析:探索动态数组的奥秘
开发语言·c++·算法
Peter_chq4 小时前
【操作系统】基于环形队列的生产消费模型
linux·c语言·开发语言·c++·后端
记录成长java5 小时前
ServletContext,Cookie,HttpSession的使用
java·开发语言·servlet