Click here to Skip to main content
15,893,904 members
Articles / Desktop Programming / MFC

CFlowchartEditor - linking things in CDiagramEditor

Rate me:
Please Sign up or sign in to vote.
4.94/5 (136 votes)
5 Jul 2006Public Domain8 min read 366K   33.9K   278  
A flowchart editor with linked objects, based on CDiagramEditor.
<html>
<header>
<style>
BODY{FONT-SIZE: 10pt;COLOR: black;FONT-FAMILY: Verdana, Helvetica, Arial, sans-serifBACKGROUND-COLOR: #ffffff}
P{FONT-SIZE: 10pt;COLOR: black;FONT-FAMILY: Verdana, Helvetica, Arial, sans-serif;}
H2{FONT-SIZE: 13pt;COLOR: #ff9900;FONT-FAMILY: Verdana, Helvetica, Arial, sans-serif;FONT-WEIGHT: bold;}
H3{COLOR: #ff9900;FONT-WEIGHT: bold;FONT-SIZE: 11pt;FONT-FAMILY: Arial, sans-serif;}
TABLE{BACKGROUND-COLOR:#f0f0ff;}
TD{FONT-SIZE: 10pt;COLOR: black;FONT-FAMILY: Verdana, Helvetica, Arial, sans-serif;PADDING:4px;}
PRE{PADDING-RIGHT: 7pt;PADDING-LEFT: 7pt;BACKGROUND-IMAGE: url(/images/codebg.gif);PADDING-BOTTOM: 7pt;FONT: 9pt "Courier New", Courier, mono;WIDTH: 100%;PADDING-TOP: 7pt;WHITE-SPACE: pre;BACKGROUND-COLOR: #fbedbb}
CODE{COLOR: #990000;FONT-FAMILY: "Courier New", Courier, mono;}
A:link{TEXT-DECORATION: none}
A:visited{TEXT-DECORATION: none}
A:active{TEXT-DECORATION: underline}
A:hover{TEXT-DECORATION: underline}
A.top:link{font-size:8pt;color:red;font-family:Verdana,Helvetica,Arial,sans-serif;}
A.top:visited{font-size:8pt;color:red;font-family:Verdana,Helvetica,Arial,sans-serif;}
A.top:active{font-size:8pt;color:red;font-family:Verdana,Helvetica,Arial,sans-serif;}
A.top:hoover{font-size:8pt;color:red;font-family:Verdana,Helvetica,Arial,sans-serif;}
</style>
</header>
<body>

<h2>CFlowchartEditor</h2>
<blockquote>The editor window. Derives from <code>CDiagramEditor</code>. In addition to the default <code>CDiagramEditor</code> implementation, it contains code for interacting with links.</blockquote>
<a class="top" href="index.html">[back to the index page]</a>&nbsp;<a class="top" href="diagrameditor.html">[base class]</a><br><a name="contents"></a>
<h3>Functions</h3>
<a href="#CFlowchartEditor">CFlowchartEditor()</a><br>
<a href="#~CFlowchartEditor">~CFlowchartEditor()</a><br>
<a href="#AdjustLinkedObjects">AdjustLinkedObjects( CFlowchartEntity* parent, CFlowchartEntity* filter = NULL )</a><br>
<a href="#CanLink">CanLink()</a><br>
<a href="#DrawGrid">DrawGrid( CDC* dc, CRect rect, double zoom ) const</a><br>
<a href="#DrawObjects">DrawObjects( CDC* dc, double zoom ) const</a><br>
<a href="#GetNamedObject">GetNamedObject( const CString& name ) const</a><br>
<a href="#IsLinked">IsLinked()</a><br>
<a href="#ModifyLinkedPositions">ModifyLinkedPositions()</a><br>
<a href="#OnKeyDown">OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)</a><br>
<a href="#OnMouseMove">OnMouseMove(UINT nFlags, CPoint point)</a><br>
<a href="#OnLink">OnLink()</a><br>
<a href="#OnLinkDirection">OnLinkDirection()</a><br>
<a href="#OnLinkProperties">OnLinkProperties()</a><br>
<a href="#OnObjectCommand">OnObjectCommand( UINT nID )</a><br>
<a href="#OnUnlink">OnUnlink()</a><br>
<a href="#SaveObjects">SaveObjects( CStringArray& stra )</a><br>

<h3>Public functions</h3>
<a name="CFlowchartEditor"></a><code>CFlowchartEditor();</code>
<blockquote>Constuctor<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="CanLink"></a><code>BOOL CanLink();</code>
<blockquote>The function returns <code>TRUE </code>is there are currently two linkable objects selected, and they can be linked. The function is intended to be used as a command enabler.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="IsLinked"></a><code>BOOL IsLinked();</code>
<blockquote>The function returns <code>TRUE </code>is there are currently two objects selected, and they are linked to each other. The function is intended to be used as a command enabler.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="OnLink"></a><code>afx_msg void OnLink();</code>
<blockquote>Command handler for the popup menu <i>Link </i>command, can also be called from code. If possible, a link is created between the two closest and free link points of the objects.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="OnLinkDirection"></a><code>afx_msg void OnLinkDirection();</code>
<blockquote>Command handler for the popup menu <i>Flip link direction </i>command, can also be called from code. If possible, the direction of the link is reversed.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="OnLinkProperties"></a><code>afx_msg void OnLinkProperties();</code>
<blockquote>Command handler for the popup menu <i>Link label </i>command, can also be called from code. If possible, the link label dialog, <code>CFlowchartLinkProperties</code>, is displayed.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="OnUnlink"></a><code>afx_msg void OnUnlink();</code>
<blockquote>Command handler for the popup menu <i>Break link </i>command, can also be called from code. If any, the link between the objects is removed.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<h3>Public virtuals</h3>
<a name="~CFlowchartEditor"></a><code>virtual ~CFlowchartEditor();</code>
<blockquote>Destructor.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<h3>Protected virtuals</h3>
<a name="DrawGrid"></a><code>virtual void DrawGrid( CDC* dc, CRect rect, double zoom ) const;</code>
<blockquote>The function draws the flowchart grid as a series of dots instead of lines.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="DrawObjects"></a><code>virtual void DrawObjects( CDC* dc, double zoom ) const;</code>
<blockquote>In addition to drawing the objects, this override also draws the links. As the <code>CFlowchartLink</code>-class don't know of coordinates or zoom, the drawing is made here rather than in the link objects themselves.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="OnKeyDown"></a><code>virtual afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);</code>
<blockquote>In addition to the default handling, linked object positions are also updated in this override.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="OnMouseMove"></a><code>virtual afx_msg void OnMouseMove(UINT nFlags, CPoint point);</code>
<blockquote>In addition to the default handling, linked object positions are also updated in this override.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="SaveObjects"></a><code>virtual void SaveObjects( CStringArray& stra );</code>
<blockquote>In addition to the default handling, links are also saved to <code>stra </code>in this override.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<h3>Private functions</h3>
<a name="AdjustLinkedObjects"></a><code>void AdjustLinkedObjects( CFlowchartEntity* parent, CFlowchartEntity* filter = NULL );</code>
<blockquote>The function loops the links, and adjust the position of objects linked to <code>parent </code>(except <code>filter</code>, if non-<code>NULL</code>). The function is called recursively, and marks moved objects as being moved to avoid infinite recursion.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="GetNamedObject"></a><code>CFlowchartEntity* GetNamedObject( const CString& name ) const;</code>
<blockquote>The function return a pointer to the object named name, or <code>NULL </code>if it isn't found (or not derived from <code>CFlowchartEntity</code>).<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>

<a name="ModifyLinkedPositions"></a><code>void ModifyLinkedPositions();</code>
<blockquote>The function calls <code>AdjustLinkedObjects </code>for all selected objects and is called after operations that might move the selected objects.<br>
<a class="top" href="#contents">[back to the contents]</a>&nbsp;<a class="top" href="index.html">[back to the index page]</a></p></blockquote>
<p><b>Johan Rosengren, Abstrakt Mekanik AB, 2004.</b></p>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Software Developer (Senior) Abstrakt Mekanik AB
Sweden Sweden
45 years old, married, three kids.

Started with computers more than 20 years ago on a CBM-64.

Read Theoretical Philosophy at the University of Lund.

Working as a C++ consultant developer.

Science-fiction freak. Enjoy vintage punkrock.

Comments and Discussions