精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。
CFlowchartEditor is an extension of CDiagramEditor. CDiagramEditor is a vector editor, with a CWnd-derived window (CDiagramEditor), a data container (CDiagramEntityContainer) holding the draw-objects, undo stack and managing copy and paste, and objects derived from CDiagramEntity representing objects drawn on screen. CDiagramEditor lacks one feature (that is difficult to implement in both simple and general fashion) - links. Manually maintaining links in a - for example - flowchart or network topography map is unwieldy. Therefore, I've created a reference implementation for one way of adding this functionality.
介绍
CFlowchartEditor是CDiagramEditor的扩展。 CDiagramEditor是一个矢量编辑器,带有CWnd派生窗口(CDiagramEditor),数据容器(CDiagramEntityContainer)支持绘图对象,撤消堆栈和管理复制和粘贴,并从CDiagramEntity代表绘制在屏幕上的对象派生的对象。 CDiagramEditor缺少一个特点(即很难实现既简单又流行) - 链接。手动保持一个环节 - 例如 - 流程图或网络拓扑图是笨拙的。因此,我创建了一个参考实现增加此功能的方法之一。
The editor can be tested in the demo application, Flowcharter. In this application, you can draw basic flowchart objects, move them around with the mouse or keyboard, cut/copy/delete/paste, undo unlimited amount of times, print-preview, and print and export the flowcharts to an EMF (enhanced metafile). If you select two unlinked objects, you can also link them. A line with an arrow showing the link direction is automatically drawn. You can select two linked objects and unlink them, reverse the link direction, or set a link label (a text moving with the link line). The objects have fixed sizes, and if a linked object is moved, other linked objects will be moved with them.
Links are automatically maintained, and if you copy and paste linked objects, the pasted objects will have the same relative links. There is even a special object, a linkable line, that can be used to create more complex flows. Note that the automatic moving will not resize objects, not even lines.
The editor also contains two un-linkable objects, a dotted line that can be used to divide the flowchart, and a label that can be used to... label the chart.
Other features from CDiagramEditor are zoom using the +/--keys, and auto-scroll when moving objects outside the visible area, as well as keyboard editing and right-click popups. You might want to download and read the CDiagramEditor documentation (link above) for a full description of the possibilities.
流程图编辑器
该编辑器可以在演示应用程序,FlowCharter中进行测试。在这个应用程序,你可以绘制基本流程图对象,动之以鼠标或键盘,剪切/复制/删除/粘贴,撤消无限量次数,打印预览,打印的流程图导出到EMF(增强型图元文件)。如果您选择了两个未链接对象,你也可以将它们链接。用箭头示出了链路方向的线被自动绘制。您可以选择两个链接的对象,并断开其链接,反向链接的方向,或设置链接的标签(文字与链接线移动)。对象具有固定的大小,并且如果链接的对象被移动时,其他链接的对象将与它们一起被移动。
链接自动维护,如果你复制和粘贴链接的对象,粘贴的对象将具有相同的相对链接。甚至有一个特殊的对象,可链接的线,可用于创建更复杂的流动。需要注意的是自动移动不会调整对象,甚至没有线。
编辑器还包含两个非可交联的对象,虚线可用来划分流程图,标签可用于...标记图表。
CdiagramEditor的其他功能使用+ / - 键缩放,移动可见区域以的外物体时自动滚动,以及键盘编辑和单击右键弹出。你可能需要下载并阅读CDiagramEditor文件(以上链接)获得可能性的完整描述。
I first made an attempt where the links were an attribute of the CDiagramEntity object, but this was, for many reasons, too complicated. Primarily, the objects started to have to know about each other, and things like copy/paste were made very difficult indeed. Instead, I went for a solution with a separate array of links in the editor container. This necessitated some modifications to CDiagramEditor, to simplify deriving from CDiagramEntityContainer (mainly making stuff either virtual, or changing them from private to protected).
Another thing I also wanted to do was a reference implementation of how to use the CDiagramEditor in a MDI-application. I soon realized a big, black blot on my architecture - it was not possible to copy and paste between several windows. Of course, as the clipboard handler was internal to the container... ripping out the clipboard handling to a separate class made this possible.
As I'm actually using the flowchart editor myself, I also needed support for enhanced metafiles, which is also added. As well as a custom right-click popup-menu for the editor (loaded from the resources, implementing link commands).
CFlowchartEditor
我首先做出了尝试,其中所述联系是CDiagramEntity对象的属性,但是这是,由于多种原因,太复杂。首先,对象开始需要了解对方,事情像复制/粘贴的确相当困难。相反,我尽力在编辑器容器链接单独阵列找到解决方案。这需要修改一些CDiagramEditor,以简化从CDiagramEntityContainer派生(主要是做的东西要么虚拟,要么将其由私有转变为受保护)。
另一件我也想要做的事是如何在MDI应用程序使用CdiagramEditor的参考实现。我很快意识到在我的体系结构有一个大的黑点-不可能在多个窗口之间复制和粘贴。当然,作为剪贴板处理程序是内部的容器......剥开剪贴板处理,使这个可能成为一个单独的类。
正如我在实际使用中的流程图编辑器,我还需要增强图元文件,这也增加了支持。还有一个自定义右键弹出菜单进行编辑(从资源加载,实现链接命令)。
If you want to add CFlowchartEditor to another application, you'll have to do the following:
Enable RTTI in your project. You do this in Project|Settings|C/C++|C++ language. CFlowchartEditor uses run time type information to be able to mix linkable and non-linkable objects. I could have used the object types (an attribute of CDiagramEntity) for this, but adding new object types would have meant that changes would have to be made in many places in the code.
Add all files of the FlowchartEditor directory, except FlowchartEditor.rc and resource.h, and all files in FlowchartEditor/DiagramEditor to your project. I do this by creating subfolders in the project - see Flowcharter.
Open your project resources and FlowchartEditor.rc at the same time. Drag - while pressing the CTRL-key - the resources from FlowchartEditor.rc to your project.
使用包
如果你想添加CFlowchartEditor到另一个应用程序,你就必须做到以下几点:
在您的项目启用RTTI。在项目|设置| C / C ++ | C ++语言这样做。 CFlowchartEditor使用运行时类型信息,以便能够混合可交联和非交联性的对象。我本可以在此使用对象类型(CDiagramEntity的属性),但添加新的对象类型意味着将有很多地方在代码作出改变。
添加FlowchartEditor目录下的所有文件,除了FlowchartEditor.rc和RESOURCE.H,和FlowchartEditor / DiagramEditor下的所有文件到项目中的所有文件。我通过创建项目子文件夹添加 - 见FlowCharter。
同时打开你的项目资源和FlowchartEditor.rc。按下CTRL键 – 将FlowchartEditor.rc资源拖到您的项目。
Add a CFlowchartEditor-member to your main dialog class.
Call CFlowchartEditor::Create in the OnInitDialog of the dialog class.
Add a CFlowchartEntityContainer-member to your CDocument-derived class.
Add the virtual function SaveModified. Add code like so:
SetModifiedFlag( m_objs.IsModified() ); return CDocument::SaveModified();
如果你有一个应用程序对话框
添加一个CFlowchartEditor成员到您的主对话框类。
在对话框类的OnInitDialog中调用CFlowchartEditor ::创建。
如果你有一个SDI应用程序
添加一个CFlowchartEntityContainer成员到您的CDocument派生类。
添加虚拟函数SaveModified。添加代码如下所示:
where m_objs is the name of your CFlowchartEntityContainer.
Modify OnNewDocument thus:
if (!CDocument::OnNewDocument()) return FALSE; m_objs.Clear(); return TRUE;
其中M_OBJS是你CFlowchartEntityContainer的名称。
这样修改OnNewDocument:
Add saving and loading in Serialize. This is an example:
增加存储和加载的序列化。这是一个例子:
if (ar.IsStoring()) { ar.WriteString( m_objs.GetString() + _T( "\r\n" ) ); int count = 0; CDiagramEntity* obj; while( ( obj = m_objs.GetAt( count++ ) ) ) ar.WriteString( obj->GetString() + _T( "\r\n" ) ); int max = m_objs.GetLinks(); for( int t = 0 ; t < max ; t++ ) { CFlowchartLink* link = m_objs.GetLinkAt( t ); if( link ) ar.WriteString( link->GetString() + _T( "\r\n" ) ); } m_objs.SetModified( FALSE ); } else { m_objs.Clear(); CString str; while(ar.ReadString( str ) ) { if( !m_objs.FromString( str ) ) { CDiagramEntity* obj = CFlowchartControlFactory::CreateFromString(str); if( obj ) m_objs.Add( obj ); else { CFlowchartLink* link = new CFlowchartLink; if( link->FromString( str ) ) m_objs.AddLink( link ); else delete link; } } } m_objs.SetModified( FALSE ); }
Note that you might want to add: 请注意,您可能需要添加:
#pragma warning( disable : 4706 )
in the top of the document class file, as well as a:
to avoid the pesky warnings.
Add a CFlowchartEditor-member to your CView-derived class. I will assume the name m_editor below.
Add the virtual function OnInitialUpdate, with (at least) this code:
Handle OnSize:
And, finally, OnEraseBkgnd:
to avoid flicker.
在文档类文件的顶部:
#pragma warning( default : 4706 )
避免烦人的警告。
添加一个CFlowchartEditor成员到您的CView派生类。我假设下面的名字m_editor。
添加虚函数OnInitialUpdate中,有(至少)这样的代码:
if( !m_editor.m_hWnd ) { // Creating the editor window CFlowcharterDoc* pDoc = GetDocument(); CRect rect; GetClientRect( rect ); m_editor.Create(WS_CHILD | WS_VISIBLE, rect, this, pDoc->GetData()); } else m_editor.Clear();
处理OnSize::
CView::OnSize(nType, cx, cy); if( m_editor.m_hWnd ) m_editor.MoveWindow(0,0,cx,cy);
最后,OnEraseBkgnd:
return TRUE;
避免闪烁。
In addition to the instructions for SDI-apps above, you should do the following:
Add a CDiagramClipboardHandler-member somewhere central. In the Flowcharter application, I opted for the application class itself. I made it public, and added an external declaration of the application object inFlowcharter.h, like so:
Modify the CView OnInitialUpdate thus:
to add a shared clipboard between all the MDI-children.
如果你有一个MDI-应用
除了上面的SDI-应用程序的说明,您应该做到以下几点:
添加CDiagramClipboardHandler名成员组成的中央地方。在FlowCharter中的应用,我选择了应用程序类本身。我做到了公开,增加了应用程序的外部声明反对inFlowcharter.h,就像这样:
extern CFlowcharterApp theApp;
修改的CView的OnInitialUpdate这样:
CView::OnInitialUpdate(); if( !m_editor.m_hWnd ) { CFlowcharterDoc* pDoc = GetDocument(); CRect rect; GetClientRect( rect ); pDoc->GetData()->SetClipboardHandler( &theApp.m_clip ); m_editor.Create( WS_CHILD | WS_VISIBLE, rect, this, pDoc->GetData() ); } else m_editor.Clear();
所有MDI-孩子之间添加共享剪贴板。
Adding metafile export is easy. As the editor already has a function to draw the diagram contents into a CDC, the following code can be used to draw a 8x11 inch diagram into a meta file:
CClientDC dc( this ); CMetaFileDC metaDC; CRect rect( 0,0, m_editor.GetVirtualSize().cx, m_editor.GetVirtualSize().cy ); // Himetric rect CRect r( 0, 0, 8 * 2540, 11 * 2540 ); metaDC.CreateEnhanced( &dc, dlg.GetPathName(), &r, _T( "FlowchartEditor Drawing" ) ); m_editor.SetRedraw( FALSE ); m_editor.Print( &metaDC, rect, 1 ); m_editor.SetRedraw( TRUE ); m_editor.RedrawWindow(); ::DeleteEnhMetaFile ( metaDC.CloseEnhanced() );
Linkable objects can be added by deriving classes from CFlowchartEntity. You'll have to add a few functions specific to your object:
AllowLinks, which should return the link points allowed. Initially, CFlowchartEntityTerminator only allowed links at the top or bottom, and exposed either LINK_TOP or LINK_BOTTOM, for example.
GetLinkPosition, which returns the position of the desired link point.
Link points can be either at the top, bottom, left, or right of the object. They can also be from the start or end of the object for lines.
You'll also want to add the functions necessary to derive from CDiagramEntity, Draw, Clone,CreateFromString, GetHitCode, GetCursor, DrawSelectionMarkers, and BodyInRect, as appropriate.
To allow reading of the objects from file, an entry will also have to be made intoCFlowchartControlFactory::CreateFromString.
You are, of course, completely free to use the source code in whatever way you want, I even grant the right to eradicate my name from all source files so you can claim you wrote it yourself This includes using the Flowcharter code - you can base a new project on the reference application, if you like.
图元文件导出
加元文件导出是容易的。由于编者已经有一个函数来绘制图表的内容到CDC,下面的代码可以用来绘制8x11英寸图成元文件:
添加对象
联性对象可以通过从CFlowchartEntity派生类添加。你必须添加几个特定的功能到你的对象:
AllowLinks,它应该返回所允许的链接点。最初,CFlowchartEntityTerminator只允许在顶部或底部的链接,并暴露在LINK_TOP或LINK_BOTTOM,例如。
GetLinkPosition,它返回所需的链接点的位置。
链接点可以在顶部,底部,左侧,或对象右侧。它们也可以是从对象的起点或终点的对线。
您还需要酌情添加由CDiagramEntity导出功能,绘图,克隆,CreateFromString,GetHitCode,GetCursor,DrawSelectionMarkers和BodyInRect派生的必要功能。
为了允许从文件中读对象,也必须作出一个intoCFlowchartControlFactory :: CreateFromString条目。
当然,你可以完全免费以任何方式使用源代码,我甚至允许从所有的源文件删除我的名字,所以你可以宣称你自己写了这些代码,这包括-如果你喜欢你可以依据参考应用在一个新的项目中使用FlowCharter代码。
The main work was already done with CDiagramEditor, and much of CFlowchartEditor is just brute coding. I'm happy with CDiagramEditor this far, the amount of work to derive new drawing objects is kept at a minimum, and it is still easy to jack in derived packages into applications of different kinds.
I realize, however, that all this might be a bunch to digest, so I've added a simplified reference implementation of links (and MDI-adaptation), CNetworkEditor.
It doesn't have any documentation for itself, except for the commented source code, but it uses the same mechanisms as CFlowchartEditor, with fewer features (linked objects are not moved, one single link point with unlimited links per object, for example), and my intention was that it could be used to compare the implementation with CFlowchartEditor. It also demonstrates the use of icons as drawing objects.
兴趣点
主要的工作已经通过CdiagramEditor完成,很多CFlowchartEditor只是蛮力编码。我很高兴与CdiagramEditor走到现在,工作要获得新的绘画对象的量保持在最低限度,派生的包仍然很容易插入不同类型的应用程序。
不过,我知道,这一切可能需要消化,所以我增加了一个简化的参考实现的链接(MDI-适应),CNetworkEditor。
它本身没有任何文档,除了注释的源代码,但它使用与CFlowchartEditor相同的机制,功能较少(链接对象不移动,具有无限连接每个对象,例如,一个单链接点)我的本意是,它可以被用来比较CFlowchartEditor实施。它还演示了使用图标作为绘画对象。
13/6 2004
As the underlying DiagramEditor is updated, I'm also updating this article so that the framework is synchronized between the two articles.
I've also updated the network map editor demo, thanks to the feedback from Dimitris Vassiliades, changing the icons to DIBs to - hopefully - give correct printouts.
8/7 2004
Another update of the DiagramEditor. I've corrected bugs, made enhancements, and added functionality:
A group command is added. Objects can be grouped and handled as a single object.
Panning is added. By clicking the middle mouse button and moving the cursor, the editor will pan the diagram.
The editor can be scrolled using the mouse wheel.
Functionality to zoom the diagram, so that all objects are visible, have been added.
The changes are documented and attributed in the diagram editor article linked above.
2004年6月13日
作为底层DiagramEditor更新,我也更新文章,以保证框架和两篇文章之间的同步。
我也更新了网络地图编辑器的演示,这要归功于从季米特里斯·Vassiliades的反馈,改变图标的??DIB来 - 希望 - 给正确的打印输出。
2004年8/7
DiagramEditor的另一个更新。我已经纠正了错误,做出改进和新增功能:
Groups
添加了一组命令。对象可以被分组,并作为一个单一的对象进行处理。
Panning
增加了Panning。通过点击鼠标中键和移动光标,编辑器会平移图像。
鼠标滚轮支持
该编辑器可以使用鼠标滚轮滚动。
缩放到适合屏幕
已添加放大图功能,以使所有的对象是可见的,。
这些变化都记录在案,并归因于图编辑器上面的文章链接。
5/8 2004
Source code updated as the DiagramEditor is updated.
28/8 2004
Far too early, here comes nevertheless a bug correction round. Once again, a big, fat thanks to you all for the feedback!
CDiagramEditor - Added check for non-normalized rect when hit-testing in OnLButtonDown, as lines have them.
CDiagramEntity - Setting m_parent to NULL in the ctor (Marc G).
CTokenizer - Changed a char to TCHAR to allow UNICODE builds (Enrico Detoma).
25/3 2005
A maintenance upgrade because of the update of the underlying CDiagramEditor.
25/6 2006
The CDiagramEditor this project is ultimately based on is updated. I've not updated the source for this article, as there are no other changes. Please use the CDiagramEditor source code - full article can be found here.
2004年5/8
因为DiagramEditor更新源代码更新。
2004年 8/28
还为时过早,这里尽管出现错误校正。再一次,非常感谢大家的反馈!
CDiagramEditor -在OnLButtonDown命中测试时增加了检查非规范化的矩形,像已有的线条。
CDiagramEntity - 在构造函数(Marc G)设置m_parent为NULL。
CTokenizer - 改变TCHAR的一个字符,允许Unicode版本(Enrico Detoma)。
2005年3/ 25
因为底层CDiagramEditor的更新的维护升级。
2006年 6/25
这个基于CDiagramEditor项目最终被更新。我还没有更新这篇文章中的资源,因为没有其他变化。请使用CDiagramEditor源代码 - 完整的文章可以在这里找到。