<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Orbifold &#187; G2</title>
	<atom:link href="http://visualizationtools.net/default/category/orbifold/products-orbifold/g2/feed/" rel="self" type="application/rss+xml" />
	<link>http://visualizationtools.net/default</link>
	<description>Think. Visualize. Understand.</description>
	<lastBuildDate>Wed, 18 Jan 2012 09:08:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>G2 and WPF mindmapping: the whole nine yards.</title>
		<link>http://visualizationtools.net/default/g2-and-wpf-mindmapping-the-whole-nine-yards/</link>
		<comments>http://visualizationtools.net/default/g2-and-wpf-mindmapping-the-whole-nine-yards/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 12:12:02 +0000</pubDate>
		<dc:creator>Francois Vanderseypen</dc:creator>
				<category><![CDATA[Diagramming]]></category>
		<category><![CDATA[G2]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Mindmapping]]></category>

		<guid isPermaLink="false">http://www.orbifold.net/default/?p=1773</guid>
		<description><![CDATA[I have completed a fully functional mindmapping application on top of G2 and have used it in the past months internally for various things. This application is, however, not a 'product' or anything you can buy, it's only a proof of concept.It's a test application, a benchmark, a toy model, a fun thing to play with and see how G2 handles various things. Much like the class designer and the database table designer I talked about earlier, it's a way to show off the potential of G2 to you, even though I think this mindmapping application could be a stepping stone to something bigger.]]></description>
			<content:encoded><![CDATA[<p><a title="Click to download the demo" href="http://www.orbifold.net/Downloads/G2/G2Demo.zip" target="_blank"><img title="Click to download the February G2 demo." src="http://www.orbifold.net/default/wp-content/uploads/g2splash.png" alt="Clcik the picture to download the demo" width="500" height="242" /></a></p>
<p>We (<a title="Denis' blog" href="http://dvuyka.spaces.live.com/default.aspx" target="_blank">Denis Vuyka 1</a>, <a title="His new site" href="http://denisvuyka.wordpress.com/" target="_blank">Denis Vuyka 2</a> and myself) have completed a fully functional mindmapping application on top of G2 and have used it in the past months internally for various things. This application is, however, not a &#8216;product&#8217; or anything you can buy, it&#8217;s only a proof of concept.It&#8217;s a test application, a benchmark, a toy model, a fun thing to play with and see how G2 handles various things. Much like <a title="The class designer" href="http://www.orbifold.net/default/?p=1735" target="_blank">the class designer</a> and<a title="The database designer" href="http://www.orbifold.net/default/?p=1764" target="_blank"> the database table designer</a> I talked about earlier, it&#8217;s a way to show off the potential of G2 to you, even though I think this mindmapping application could be a stepping stone to something bigger.</p>
<p>This said, the development was a lot of work; the devil is in the details as everyone knows. G2 is a framework on top of which you can create an application, attach meaning to nodes and links, handle events and trigger some mechanism in the G2 core and so on, all this is conceptually quite easy. Making things smooth on the UI level, making custom controls to manipulate the data coming or going to G2 is on the other hand a tedious process of UI-design, usability testing/trying, debugging, handling special cases (large images, bad alignment of text, broken serialization due to unicode characters&#8230;) and more. This journey has been rewarding, once you have the idiosyncrasies of WPF in your fingers and can navigate blindly through G2, the whole process feels very productive.Â  For example, creating a thought-node which binds to some RSS and injects blog-titles into the map is fun and easy, the same for custom nodes binding to stocks &amp; shares data (see the screenshots). Creating thought-nodes with clickable icons or showing some custom data is a no-brain activity. In fact, because the stuff shown on a node is presented through WPF&#8217;s databinding you can add pretty much anything you like to the node&#8217;s visual.</p>
<div id="attachment_1781" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/stocksshares.png"><img class="size-medium wp-image-1781" title="stocks and shares" src="http://www.orbifold.net/default/wp-content/uploads/stocksshares-300x187.png" alt="Money mindmap" width="300" height="187" /></a>
<p class="wp-caption-text">Stocks &amp; shares</p>
</div>
<div id="attachment_1794" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/renderings.png"><img class="size-medium wp-image-1794" title="renderings" src="http://www.orbifold.net/default/wp-content/uploads/renderings-300x187.png" alt="Mindmap on 'rendering'" width="300" height="187" /></a>
<p class="wp-caption-text">Mindmap on &#39;rendering&#39;</p>
</div>
<div id="attachment_1795" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/theorbifold.png"><img class="size-medium wp-image-1795" title="theorbifold" src="http://www.orbifold.net/default/wp-content/uploads/theorbifold-300x187.png" alt="About The Orbifold" width="300" height="187" /></a>
<p class="wp-caption-text">About The Orbifold</p>
</div>
<div id="attachment_1775" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/standardmm.png"><img class="size-medium wp-image-1775" title="Standard MM design" src="http://www.orbifold.net/default/wp-content/uploads/standardmm-300x133.png" alt="The classic mindmapping layout." width="300" height="133" /></a>
<p class="wp-caption-text">The classic mindmapping layout.</p>
</div>
<p>I&#8217;ll review a bit the features of the application which obviously reflect the features and capacity of G2 as a basis for diagramming in general.</p>
<p><span id="more-1773"></span></p>
<h2>Standard features</h2>
<div id="attachment_1786" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/menustructure.png"><img class="size-medium wp-image-1786" title="menu structure" src="http://www.orbifold.net/default/wp-content/uploads/menustructure-300x58.png" alt="Menu items" width="300" height="58" /></a>
<p class="wp-caption-text">Menu items</p>
</div>
<ul>
<li>Saving to the internal binary format (*.g2d) and to XML (*.xml). You can alter the generated XML and open it up again. At some point I&#8217;ll publish the XML data format but you can experiment and find out yourself as well.</li>
<li>Opening diagram from binary and XML formats. Both formats support multiple pages inside a single document.</li>
<li>Creating a new document (<strong>CTRL+N</strong>) will request by default if you wish to save the current document first.</li>
<li><strong>CTRL+S</strong> and <strong>CTRL+O </strong>are bound and subsequent savings will first try the current file path. If you wish to save it elsewhere you can use SaveAs (no input binding here), but all this is pretty standard.</li>
</ul>
<p>Note that a document (a mindmapping document in this demo) consists of some <strong>metadata </strong>and one or more <strong>pages</strong>. A page is much like a sheet in Microsoft Office Excel or Visio. Internally a page is furthermore subdivided into layers but in this demo you will not be able to have mutliple layers. In fact, it&#8217;s rather difficult to conceptually give meaning to layers in a mindmapping diagram.</p>
<div id="attachment_1788" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/multipgae.png"><img class="size-medium wp-image-1788" title="multiple pages" src="http://www.orbifold.net/default/wp-content/uploads/multipgae-300x56.png" alt="Multi-page tab" width="300" height="56" /></a>
<p class="wp-caption-text">Multi-page tab</p>
</div>
<p>Page can be added through the toolbar item entitled &#8216;Add page&#8217; and removed or renamed through the tabpage context menu. A document has at least one page, which means you cannot delete the page if it&#8217;s the only one in the document. See also the know issue related to the tabs below.</p>
<p><strong>Cut, copy, paste and delete (CCPD) </strong>need little explanations, I guess. Mind though that when navigating the diagram with the keyboard the focus is on the text inside the shapes. This means that at that moment CCPD has its effect on the text and not on the shapes. In order to CCPD shapes the focus needs to be on the diagram level. Just use the traditional rubber-band (marching ants, selector) to select shapes (use CTRL or SHIFT to add to an existing selection) and CCPD then. In this context I need to note that if you select multiple shapes which have a parent relationship (like in the screeenshot below) the upper parent will be used and hence all children underneath will be used in the CCPD process. This system ensures that no shape becomes an orphan in the CCPD process.</p>
<div id="attachment_1789" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/ccpd.png"><img class="size-medium wp-image-1789" title="CCPD" src="http://www.orbifold.net/default/wp-content/uploads/ccpd-300x181.png" alt="Illustrating the obvious" width="300" height="181" /></a>
<p class="wp-caption-text">Illustrating the obvious</p>
</div>
<p>The <strong>O2 docking environment</strong> is an in-house development based on MEF, AvalonDock and Denis&#8217; wonderful propertygrid (though in this demo it&#8217;s been hidden). The <strong>View menu </strong>allows you to bring up the various panels of the demo. Most notably, the<strong> Output window</strong> will display internal messages or (worse) exceptions and<strong> the internal browser</strong> is just a WPF Frame (hence, wrapped IE ). The docking layout can be saved via the <strong>Tools menu</strong> and re-opened later on.</p>
<p>Nothing spectacular but anyway, you can select a custom background for a diagram which in some cases can really make a diagram more attractive. With WPF there are so many possibilities&#8230;</p>
<div id="attachment_1798" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/backgrounds.png"><img class="size-medium wp-image-1798" title="backgrounds" src="http://www.orbifold.net/default/wp-content/uploads/backgrounds-300x219.png" alt="Custom diagram backgrounds" width="300" height="219" /></a>
<p class="wp-caption-text">Custom diagram backgrounds</p>
</div>
<p>Editing the diagram metadata (author, date and title), <strong>zooming </strong>and assigning an <strong>icon </strong>can all be done through the<strong> Diagram elements</strong> panel. There is also a <strong>thumbnail view</strong> which in a later phase will allow you to navigate the diagram, but I haven&#8217;t put much focus on this lately. Zooming can also be achieve via the mousewheel and pressing the CTRL key (quite standard nowadays). To reset the zoom factor just press/click the mousewheel (yes, you can press the wheel). An addition which I have overlooked as I&#8217;m writing this is the SHIFT with the mousewheel which in most applications allows you to scroll horizontally.</p>
<div id="attachment_1791" class="wp-caption alignnone" style="width: 160px"><a href="http://www.orbifold.net/default/wp-content/uploads/elements.png"><img class="size-thumbnail wp-image-1791" title="elements" src="http://www.orbifold.net/default/wp-content/uploads/elements-150x150.png" alt="Diagram elements panel" width="150" height="150" /></a>
<p class="wp-caption-text">Diagram elements panel</p>
</div>
<h2>Mindmapping specific features</h2>
<p>Besides the features which are available to every G2 diagram type (or part of the O2 environment), there are also a few things specific to mindmapping which we&#8217;ll highlight below.</p>
<div id="attachment_1800" class="wp-caption alignnone" style="width: 160px"><a href="http://www.orbifold.net/default/wp-content/uploads/customstyles.png"><img class="size-thumbnail wp-image-1800" title="customstyles" src="http://www.orbifold.net/default/wp-content/uploads/customstyles-150x150.png" alt="Mindmapping toolbar" width="150" height="150" /></a>
<p class="wp-caption-text">Mindmapping toolbar</p>
</div>
<p>One of the very productive features of WPF is the possibility <strong>to style or template a control</strong>. When you select a thought-shape you can alter its appearance through the dropdown in the toolbar (see screenshot). For this demo I created <strong>some custom styles</strong> which suit different data bucket but, as I described above, the possibilities are limitless and easily implemented. Take this together with the databinding and you have a mindmapping framework for every possible (business) context.</p>
<div id="attachment_1801" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/customstyle2s.png"><img class="size-medium wp-image-1801" title="customstyle2s" src="http://www.orbifold.net/default/wp-content/uploads/customstyle2s-300x207.png" alt="An overview of some styles defined in the demo" width="300" height="207" /></a>
<p class="wp-caption-text">An overview of some styles defined in the demo</p>
</div>
<ul>
<li><strong>CTRL+R</strong> rotates the diagram</li>
<li><strong>CTRL+ENTER</strong> adds a child node. Some dummy text is auto-generated which eases the testing process and easily creates maps in no time. As this is some kind of &#8216;random book-title generator&#8217; you can have sometimes rather strange or funny titles <img src='http://visualizationtools.net/default/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li><strong>CTRL+T</strong> switches between editing the text or thought title inline and editing the body text</li>
<li><strong>CTRL+M</strong> expands/collapses the children of the selected node</li>
<li><strong>CTRL+ARROW</strong> allows you to navigate the map through the keyboard. This togheter with CTRL+ENTER makes it easy to create dummy maps in no time.</li>
</ul>
<p><strong>Drag-drop.</strong> If a node is selected and you dragdrop an URL it will be attached to the selected node. If you dragdrop an image from the file explorer this will create a new child node to the <span style="text-decoration: underline;">selected node</span>. Nothing will be created if no node is selected!</p>
<p><strong>The thought editor.</strong> The data displayed in a shape is, as said earlier, just a data bucket bound to the visual in the diagram. For example, below is the definition of the &#8216;Shares&#8217; shape template wherein you can see the different data bindings. So, in effect there is just a collection of data islands which you can bind both to the shape in the diagram but also to some editor. Altering the data in one will change the data everywhere else, which demonstrates brilliantly the power of WPF&#8217;s databinding. The though editor is a dockable panel which allows to change the data island and it&#8217;s rather self-descriptive. You can add some URL&#8217;s or some files to a thought through the listviews, change the body text, add an icon or change the title inline. Obviously the whole editor would be even more useful if RTF-ed or HTML-ed but I did not want to waste too much time on this. Ultimately, it&#8217;s just plugging in some open source or commercial editor since the data bucket only cares about the string result.</p>
<div id="attachment_1802" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/sharestemplate.png"><img class="size-medium wp-image-1802" title="sharestemplate" src="http://www.orbifold.net/default/wp-content/uploads/sharestemplate-300x219.png" alt="The 'Shares' template" width="300" height="219" /></a>
<p class="wp-caption-text">The &#39;Shares&#39; template</p>
</div>
<p>One word of warning for those thinking that adding shapes and styles is only a matter of adding properties and changing the XAML. The underestimated part behind CCPD and saving documents is the whole (de)serialization process; making sure databinding works after deserialization, picking up the styles from the assembly&#8217;s resources, disassembling the layout organization, figuring out how to maintain the mindmap hierarchy and so on. To the rescue, the data exchange pipeline (aka. G2D) inside G2 maximizes flexibility through some smart usage of Unity (as<a title="About Unity and extensibility in G2" href="http://www.orbifold.net/default/?p=1130" target="_blank"> explained elsewhere on this blog</a>) which allows us to really change the import/export of XML in a snap, embrace data changes with ease and be prolific without having to step through the (de)serialization on a low level (anymore).</p>
<h2>Things left out</h2>
<ul>
<li>Other types of diagrams are not possible in this demo (though the XML manipulation will not stop you from getting there).</li>
<li>Saving data to a WCF endpoint or database backend.</li>
<li>Dragging thought-shapes and altering the map via the mouse.</li>
<li>The possibility to mix free shapes and thought-shapes.</li>
<li>Layers (see also my remark above).</li>
<li>Saving/opening sub-document elements.</li>
<li>Active shapes (RSS shape, Google search shape and other &#8216;intelligent&#8217; shapes).</li>
</ul>
<p>All these things are possible with G2 but I think the current demo is sufficient (for now) as other diagram types need attention as well&#8230;</p>
<h2>What&#8217;s the point?</h2>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/magritte.jpg"><img style="float:left;margin:10px;" title="Ceci n est pas une pipe" src="http://www.orbifold.net/default/wp-content/uploads/magritte-300x221.jpg" alt="Ceci n est pas une pipe" width="300" height="221" /></a>To paraphrase <a title="ceci n'est pas une pipe" href="http://www.magritte.com/" target="_blank">my compatriot</a>; <em>ceci n&#8217;est pas un logiciel</em>. <strong>It&#8217;s a demo</strong> (I&#8217;d almost say a fancy UI facade on top of) showing what can be done with G2. The diagrams I talked about in other blog postings will be integrated in the near future to complete the demo so that in the end a more &#8216;covering&#8217; picture appears of what G2 is. There as been an enormous interest in G2 and Graphite in the past months but unfortunately we have not been able to deliver a downloadable demo on time. I hope this first release already satisfies a bit the hungry (customer) minds out there.</p>
<p>You can do as you wish with this demo, there are no constraints. Of course, any feedback is welcome. If you really have the burning wish to turn this demo in something you think is worth selling you can <a title="Drop me a mail" href="http://www.orbifold.net/default/?page_id=1257" target="_self">drop me a mail</a>, custom solution requests and business opportunities are <a title="Business opportunities" href="http://www.orbifold.net/default/?page_id=1257">welcome as well</a>.</p>
<p>The next download of the G2 demo wil contain the other diagramming types, but no schedule on the table for now. We are developing custom diagramming controls for customers, elaborate data visualizations in our lab, handle heaps of mails and questions, have a fulltime job next to all this and take care of our family. Acrobatic challenges at times. Most probably you&#8217;ll see signs on this site of our other projects before the next G2 drop.</p>
<p><a title="Download the G2 demo" href="http://www.orbifold.net/Downloads/G2/G2Demo.zip" target="_blank">Download the February G2 mindmapping demo.</a></p>
<h2>Known issues</h2>
<p><strong>.Net v3.5 SP1 is required to run this demo.</strong> You can <a title=".Net 3.5 sp1" href="http://msdn.microsoft.com/en-us/vstudio/cc533448.aspx" target="_blank">download all this from MSDN</a>.</p>
<p><strong>The virtual double.</strong> This occurs when you load a document and the page tab control shows a double of some page. When you click on either when the other virtual double will disappear. This is a bug in the databinding for which I was unable to find an answer or trace the cause.</p>
<div id="attachment_1787" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/virtualdouble.png"><img class="size-medium wp-image-1787" title="virtual double" src="http://www.orbifold.net/default/wp-content/uploads/virtualdouble-300x129.png" alt="Doubling of pages on load" width="300" height="129" /></a>
<p class="wp-caption-text">Doubling of pages on load</p>
</div>
<p><strong>Sub-document file types. </strong>The open/save dialogs present you alternative file extensions (*.g2s, *.g2b, *.g2p). These types are not supported in this demo, though the serialization is inside G2. These extensions allow one to save only a page, a subset of shapes or just one single shape to a file. These types are useful to load <strong>templates </strong>and re-use single shapes in other documents.</p>
<div id="attachment_1796" class="wp-caption alignnone" style="width: 310px"><a href="http://www.orbifold.net/default/wp-content/uploads/supportedfiletypes.png"><img class="size-medium wp-image-1796" title="supportedfiletypes" src="http://www.orbifold.net/default/wp-content/uploads/supportedfiletypes-300x256.png" alt="Other file types" width="300" height="256" /></a>
<p class="wp-caption-text">Other file types</p>
</div>
<p><strong>Undo/redo. </strong>The undo/redo mechanism is not everywhere properly bound to the actions. This is not a bug in G2 but rather a badly bound UI to the underlying core.<strong> </strong>Sorry.<strong><br />
</strong></p>
<p><em>Semantic note: <a title="Etymology of this" href="http://en.wikipedia.org/wiki/The_whole_nine_yards" target="_blank">the whole nine yards</a>: means &#8220;completely, the whole, everything.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://visualizationtools.net/default/g2-and-wpf-mindmapping-the-whole-nine-yards/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating database diagrams with G2</title>
		<link>http://visualizationtools.net/default/creating-database-diagrams-with-g2/</link>
		<comments>http://visualizationtools.net/default/creating-database-diagrams-with-g2/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 20:51:41 +0000</pubDate>
		<dc:creator>Francois Vanderseypen</dc:creator>
				<category><![CDATA[Diagramming]]></category>
		<category><![CDATA[G2]]></category>

		<guid isPermaLink="false">http://www.orbifold.net/default/?p=1764</guid>
		<description><![CDATA[How G2 is also able to create, visualize and edit database related information.]]></description>
			<content:encoded><![CDATA[<p>No surprise here I guess, this is a variation on <a title="Creating class diagrams with G2." href="/default/?p=1735">my ealier posting</a> but now on the basis of database information rather than assembly (reflected) data.</p>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/g2dbdiagram.png" target="_blank"><img class="alignleft size-medium wp-image-1765" title="DB diagrams with G2" src="http://www.orbifold.net/default/wp-content/uploads/g2dbdiagram-300x178.png" alt="DB diagrams with G2" width="300" height="178" /></a></p>
<p>Althoug it might look like a piece of cake to display this kind of information and it seems like a simple shift from the class shape discussed earlier, it was quite a challenge to dot it. Not so much the diagramming part but the data grid inside the shape was somewhat difficult. While there is <a title="WPF's datagrid." href="http://www.codeplex.com/wpf" target="_blank">a datagrid for WPF</a> it would be a heavy load on the diagramming surface to include it in the shape containers. So, the only option was to create a home-made lightweight datagrid. In addition, it had to have an inline editing capability in the form of comboboxes, textboxes, checkboxes and more. Finally, I also wanted the whole shape to have different view states; totally collapsed, names only and the full datagrid view.</p>
<p>In the picture you can see a sample diagram with the various features;</p>
<ul>
<li>the User &amp; Countries tables are &#8216;full&#8217;, the Credential table is in a collapsed state and the Address table shows only the names of the fields. The upper-right icon allows you to cycle through the different views. This is not mendatory, however, as the icon simply launches a routed command which can be captured anywhere and you can call the ShowCollapsed(), ShowNamesOnly and ShowFull() methods on the original source to changes the view as you like.</li>
<li>the lines in bold in the grid show either the active record or the primary key(s)</li>
<li>double clicking allows one to edit the fields</li>
<li>the labels can contain in general the info you like and it&#8217;s a generic feature of G2 rather than part of the database related shape info.</li>
</ul>
<p>Although I did not fully develop things, one can go the full nine yards and turn this sample into either a database visualizer or a database editor (or both) much like in SQL Server&#8217;s management studio. Using the integrated analysis service of G2 one could also traverse the diagram and create scripts or XML on top of it. Well, you got the point I guess.</p>
]]></content:encoded>
			<wfw:commentRss>http://visualizationtools.net/default/creating-database-diagrams-with-g2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating class diagrams with G2</title>
		<link>http://visualizationtools.net/default/creating-class-diagrams-with-g2/</link>
		<comments>http://visualizationtools.net/default/creating-class-diagrams-with-g2/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 20:55:40 +0000</pubDate>
		<dc:creator>Francois Vanderseypen</dc:creator>
				<category><![CDATA[Diagramming]]></category>
		<category><![CDATA[G2]]></category>

		<guid isPermaLink="false">http://www.orbifold.net/default/?p=1735</guid>
		<description><![CDATA[Wherein I explain how G2 was used to create class diagrams. Some notes on XML (de)serialization of G2 diagrams and the upcoming workflow designer.]]></description>
			<content:encoded><![CDATA[<p>As a proof of concept for some customer I created recently some class diagrams in G2. The purpose was the following; to be able to drag-drop assembly items on a diagram surface much like one does inside Visual Studio and to have the same kind of coloring and auto-connecting of inter-related classes (i.e. inheritance). As a to-be-visualized assembly I took the G2 assembly itself. So, in a way G2 is reflecting itself in this application.</p>
<p>Part of the work consisted in creating some smart reflection code. Fortunately, nowadays one can do things in a flash through LINQ, so this was done in no time.</p>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/g202first.png"><img src="http://www.orbifold.net/default/wp-content/uploads/g202first-300x178.png" alt="G2/O2 with class diagrams." title="G2/O2 with class diagrams." width="300" height="178" class="alignnone size-medium wp-image-1738" /></a></p>
<p><span id="more-1735"></span></p>
<p>Another part consisted in customizing my O2 presentation environment which has the look-and-feel of Microsoft Blend and a bit of Visual Studio as well. The code is largely based on the <a title="The AvalonDock project" href="http://www.codeplex.com/AvalonDock" target="_blank">AvalonDock</a> project and on <a title="WPF property grid" href="http://www.codeplex.com/wpfpropertygrid" target="_blank">Denis Vuyka&#8217;s property grid</a>. The big challenge here was to merge and harmonize the code into one smooth framework. At some point I considered to merge some <a title="CompositeWPF" href="http://www.codeplex.com/CompositeWPF" target="_blank">WPF composition</a> ideas as well but due to the horrendous learning curve and the P&amp;P&#8217;s complicated ideas around multi-targetting their framework I set the idea aside. Still, I believe that as it stands now the O2 code is well suited to develop within it a variety of (commercial) applications. See the screenshots and note, by the way, how nicely the browser and The Orbifold&#8217;s website blends into the application.</p>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/g202browserintegration.png"><img src="http://www.orbifold.net/default/wp-content/uploads/g202browserintegration-300x178.png" alt="Browser and site integration in G2/O2" title="Browser and site integration in G2/O2" width="300" height="178" class="alignnone size-medium wp-image-1739" /></a></p>
<p>Finally, the biggest part of my efforts went into creating the &#8216;class shape&#8217;Â  or, as it&#8217;s called internally, the TreeviewShape. Let me highlight a bit the anatomy of the shape and how the serialization of it is implemented.</p>
<p>The shape is organized more or less like this (see also the XAML template below):</p>
<ul>
<li>The head consists of the colored (rounded) rectangle inside which multiple headers can be place, all of which can have a distinct icon. The icon which allows you to collapse/expand the shape is in fact a templated button. The whole head (see the TranslationHeader style below) can catch the mouse in order to move the shape around and is in fact itself a templated control.  </li>
<li>The body is really just a standard WPF TreeView. However, it took me an eternity to make it look OK and to position it inside the template. The reason being that the order in which one places the various XAML tags is important and there are some quirks in the WPF framework (no mouse recognition if there is no background, for instance). This said, I should underline that all of this is nothing in comparison to what it once required before WPF was among us (cfr. the class-shape in Netron in this context).</li>
</ul>
<p>The most time-consuming part of the work is in fact the little details and the parametrization of the various XAML attributes in order to make sure that the layout works for all possible situations.</p>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/g202treeviewshape.png"><img src="http://www.orbifold.net/default/wp-content/uploads/g202treeviewshape.png" alt="The TreeViewShape" title="The TreeViewShape" width="470" height="296" class="alignnone size-full wp-image-1740" /></a></p>
<div class="wp_codebox">
<table>
<tr id="p17351">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre>
</td>
<td class="code" id="p1735code1">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;{x:Type Core:TreeviewShape}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;MinWidth&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;125&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;MinHeight&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;28&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;SnapsToDevicePixels&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;True&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Template&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setter<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;setter</span> .Value<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controltemplate</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;{x:Type Core:TreeviewShape}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;border</span> <span style="color: #000066;">BorderBrush</span>=<span style="color: #ff0000;">&quot;White&quot;</span>   <span style="color: #000066;">CornerRadius</span>=<span style="color: #ff0000;">&quot;10&quot;</span>  <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">BorderThickness</span>=<span style="color: #ff0000;">&quot;1,1,1,2&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;White&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_maingrid&quot;</span> <span style="color: #000066;">DataContext</span>=<span style="color: #ff0000;">&quot;{Binding RelativeSource={RelativeSource TemplatedParent}}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stackpanel</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Vertical&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
              <span style="color: #808080; font-style: italic;">&lt;!-- PART_TranslationOverlay --&gt;</span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;core</span> :TranslationOverlay <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{StaticResource TranslationHeader}&quot;</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_TranslationOverlay&quot;</span> <span style="color: #000066;">Cursor</span>=<span style="color: #ff0000;">&quot;SizeAll&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeview</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;0,0,0,5&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{StaticResource xxx}&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span>  <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;tree&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/stackpanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;core</span> :ConnectorDecorator <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_ConnectorDecorator&quot;</span></span>
<span style="color: #009900;">                         <span style="color: #000066;">Visibility</span>=<span style="color: #ff0000;">&quot;Hidden&quot;</span></span>
<span style="color: #009900;">                         <span style="color: #000066;">Template</span>=<span style="color: #ff0000;">&quot;{StaticResource ConnectorDecoratorTemplate}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/border<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controltemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;controltemplate</span> .Triggers<span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #808080; font-style: italic;">&lt;!--&lt;dataTrigger Value=&quot;True&quot; Binding=&quot;{Binding RelativeSource={RelativeSource Self},Path=IsSelected}&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">                &lt;setter TargetName=&quot;PART_ResizeDecorator&quot; Property=&quot;Visibility&quot; Value=&quot;Visible&quot;/&gt;</span>
<span style="color: #808080; font-style: italic;">              --&gt;</span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;trigger</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;IsMouseOver&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setter</span> <span style="color: #000066;">TargetName</span>=<span style="color: #ff0000;">&quot;PART_ConnectorDecorator&quot;</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Visibility&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Visible&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/trigger<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;datatrigger</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;True&quot;</span> <span style="color: #000066;">Binding</span>=<span style="color: #ff0000;">&quot;{Binding RelativeSource={RelativeSource Self},Path=IsDragConnectionOver}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setter</span> <span style="color: #000066;">TargetName</span>=<span style="color: #ff0000;">&quot;PART_ConnectorDecorator&quot;</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Visibility&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Visible&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/datatrigger<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controltemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</td>
</tr>
</table>
</div>
<div class="wp_codebox">
<table>
<tr id="p17352">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre>
</td>
<td class="code" id="p1735code2">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;TranslationHeader&quot;</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;{x:Type Core:TranslationOverlay}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Background&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setter<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;setter</span> .Value<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lineargradientbrush</span> <span style="color: #000066;">EndPoint</span>=<span style="color: #ff0000;">&quot;1,0&quot;</span> <span style="color: #000066;">StartPoint</span>=<span style="color: #ff0000;">&quot;0,0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradientstop</span> <span style="color: #000066;">Color</span>=<span style="color: #ff0000;">&quot;#9FB6CD&quot;</span> <span style="color: #000066;">Offset</span>=<span style="color: #ff0000;">&quot;0.50&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradientstop</span> <span style="color: #000066;">Color</span>=<span style="color: #ff0000;">&quot;#FFF&quot;</span> <span style="color: #000066;">Offset</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lineargradientbrush<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Template&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setter<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;setter</span> .Value<span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;controltemplate</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;{x:Type Core:TranslationOverlay}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;border</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_HeaderBorder&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;{TemplateBinding Background}&quot;</span> <span style="color: #000066;">CornerRadius</span>=<span style="color: #ff0000;">&quot;10,10,0,0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_HeaderGrid&quot;</span> <span style="color: #000066;">MinHeight</span>=<span style="color: #ff0000;">&quot;60&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;184&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;60&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/grid<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;grid</span> .ColumnDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;columndefinition</span> <span style="color: #000066;">MinWidth</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;140*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;columndefinition</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;19*&quot;</span> <span style="color: #000066;">MinWidth</span>=<span style="color: #ff0000;">&quot;19&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;grid</span> .RowDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rowdefinition</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;25*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rowdefinition</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;25*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rowdefinition</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;25*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stackpanel</span> <span style="color: #000066;">Grid.ColumnSpan</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;0,2,0,0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;image</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_HeaderIcon&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">MaxHeight</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">MaxWidth</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;5,0,0,0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textblock</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_Header&quot;</span>    <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;BezierConnection&quot;</span>    <span style="color: #000066;">Foreground</span>=<span style="color: #ff0000;">&quot;#FF000000&quot;</span> <span style="color: #000066;">TextTrimming</span>=<span style="color: #ff0000;">&quot;CharacterEllipsis&quot;</span> <span style="color: #000066;">TextWrapping</span>=<span style="color: #ff0000;">&quot;NoWrap&quot;</span> <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;12&quot;</span> <span style="color: #000066;">FontWeight</span>=<span style="color: #ff0000;">&quot;Bold&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">MaxWidth</span>=<span style="color: #ff0000;">&quot;120&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;5,0,0,0&quot;</span> <span style="color: #000066;">FontFamily</span>=<span style="color: #ff0000;">&quot;Tahoma&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/stackpanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{StaticResource SwitchButton}&quot;</span>  <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Left&quot;</span> <span style="color: #000066;">Grid.Column</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;0,0,2,0&quot;</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_ExpandButton&quot;</span> <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Top&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stackpanel</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;2,0,5,0&quot;</span> <span style="color: #000066;">Grid.ColumnSpan</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;image</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_SubHeaderIcon&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">MaxHeight</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">MaxWidth</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;3,0,0,0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textblock</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_SubHeader&quot;</span>  <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Foreground</span>=<span style="color: #ff0000;">&quot;#FFFFFFFF&quot;</span>  <span style="color: #000066;">TextWrapping</span>=<span style="color: #ff0000;">&quot;Wrap&quot;</span> <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;11&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;5,0,0,0&quot;</span> <span style="color: #000066;">FontFamily</span>=<span style="color: #ff0000;">&quot;Tahoma&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/stackpanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stackpanel</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;2,0,5,0&quot;</span> <span style="color: #000066;">Grid.ColumnSpan</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;image</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_SubSubHeaderIcon&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">MaxHeight</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">MaxWidth</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;3,0,0,0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;textblock</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PART_SubSubHeader&quot;</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;Auto&quot;</span> <span style="color: #000066;">Foreground</span>=<span style="color: #ff0000;">&quot;#FFFFFFFF&quot;</span>  <span style="color: #000066;">TextWrapping</span>=<span style="color: #ff0000;">&quot;Wrap&quot;</span>  <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;11&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;5,0,0,0&quot;</span> <span style="color: #000066;">FontFamily</span>=<span style="color: #ff0000;">&quot;Tahoma&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/stackpanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/border<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/controltemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</td>
</tr>
</table>
</div>
<p>Finally, <strong>the serialization part</strong>. This is really where G2 shines, I think. I probably invested half a year into the data-exchange pipeline of G2 but looking now how much the development benefits from this I&#8217;m really happy I went through this difficult development period.<br />
The data exchange pipeline (called internally G2D) is a rather complex piece of software which to some extend is explained in my series of articles on Unity and Unity extensions. It basically consists of &#8216;actions&#8217; which sit inside the Unity container and are orchestrated into one &#8216;transaction&#8217; to achieve various things like binary serialization, XML serialization, copy/paste and the creation of undo/redo units of (diagramming) work. It might come as a suprise but probably half of the code of G2 has to do with serialization and data exchange and only a minor part is related to visualization and layout.<br />
Anyway, the data-exchange code (note that this entails more than just serialization) of the TreeViewShape consists of three parts:</p>
<ul>
<li>the <strong>data-bucket </strong>or the serialization counterpart of the shape. This is a true data-entity much like one has in data access layers of a N-tiered database application. It contains the presentation-independent stuff of the shape and can be serialized to any repository (database, WCF, XML, binary files). </li>
<li>The <strong>converter </strong>between the shape and the data-entity. This can be compared to a mapping layer. Actually, the whole G2D pipeline is much like the Entity Framework as far as functionality is concerned. One could really take the G2D code and generalize it with little efforts to a generic data mapping layer.</li>
<li>a lot of <strong>XML fine-tuning</strong> in order to make WPF things XML-readable. Some would use here the out-of-the-box XAML-writer but I discovered after many failures that the XAML reader/writer of WPF has some limitations and is not suitable if you wish to have a bit of control on what is being outputted.
</li>
</ul>
<p>I will discuss in a separate article <strong>the beautiful XML features of G2</strong> but let me briefly here show how easy one can create or modify diagrams through XML. Below is a snippet of G2 XML which serializes a single G2 page with a single layer and in this layer two treeview shapes. Now, it doesn&#8217;t require a PhD to see what it all means and to modify things; connections, layers, pages and other shapes are added in a snap. Don&#8217;t get confused by the many GUID&#8217;s, they are internally generated and can be replaced by your own ID&#8217;s. This means in fact that these ID&#8217;s could have some meaning inside your applications (database record ID&#8217;s for example) and that the XML could be generated outside G2. In addition, G2 allows you to import parts of diagramming documents like pages or bundles of shapes and connections. This then, in effect, allows you to import parts of diagrams from multiple source which then merge into one document. For example, it&#8217;s perfectly possible to use multiple WCF services (the data buckets are WCF-ready and serializable through WCF) to feed one diagram.</p>
<p>To conclude, somewhere soon I&#8217;ll also demonstrate how G2 can be used to <strong>create workflow diagrams</strong> in the same fashion. I also intend to create a <a href="http://msdn.microsoft.com/en-us/library/ms735921.aspx" target="_blank">XOML </a>importer which would enable one to model WF models outside Visual Studio, but considering the upcoming WF 4.0 and its many new features I think I&#8217;d better wait until .Net 4.0 is released.</p>
<div class="wp_codebox">
<table>
<tr id="p17353">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre>
</td>
<td class="code" id="p1735code3">
<pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000066;">standalone</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gradium</span> <span style="color: #000066;">Version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;document<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;metadata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;creationdate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2009-01-05T19:35:12.4154+01:00<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/creationdate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/metadata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;page</span> <span style="color: #000066;">AutoLayout</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">AutoConnect</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">IsActivePage</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">PageType</span>=<span style="color: #ff0000;">&quot;ConceptMap&quot;</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;e5e78121-55c3-422c-a423-39b681fca3c8&quot;</span> <span style="color: #000066;">Title</span>=<span style="color: #ff0000;">&quot;Concept map&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connections</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;layer</span> <span style="color: #000066;">Visible</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">IsDefaultLayer</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">Title</span>=<span style="color: #ff0000;">&quot;Default layer&quot;</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;bba7b83a-718c-4305-a6a8-5274d4174351&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;shapes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewshape</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;365b6faf-44e6-4dce-9b28-975990da3ced&quot;</span> <span style="color: #000066;">Size</span>=<span style="color: #ff0000;">&quot;NaN (Niet-een-getal);NaN (Niet-een-getal)&quot;</span> <span style="color: #000066;">Location</span>=<span style="color: #ff0000;">&quot;1013;546,04&quot;</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;BezierConnection&quot;</span> <span style="color: #000066;">SubHeader</span>=<span style="color: #ff0000;">&quot;Class&quot;</span> <span style="color: #000066;">SubSubHeader</span>=<span style="color: #ff0000;">&quot;ConnectionBase&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connector</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;b9137087-095e-45f5-b92a-04a640b9bc83&quot;</span> <span style="color: #000066;">Layer</span>=<span style="color: #ff0000;">&quot;Left&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Left&quot;</span> <span style="color: #000066;">Position</span>=<span style="color: #ff0000;">&quot;1014;599,5&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connector</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;98075af4-77c0-45fa-a407-cc0d7d272643&quot;</span> <span style="color: #000066;">Layer</span>=<span style="color: #ff0000;">&quot;Top&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Top&quot;</span> <span style="color: #000066;">Position</span>=<span style="color: #ff0000;">&quot;1106;547,04&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connector</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;e1b496f0-f393-4556-a0db-4b6935831a4f&quot;</span> <span style="color: #000066;">Layer</span>=<span style="color: #ff0000;">&quot;Right&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Right&quot;</span> <span style="color: #000066;">Position</span>=<span style="color: #ff0000;">&quot;1198;599,5&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connector</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;e1c800dc-7014-41d1-9930-280a6c317f3c&quot;</span> <span style="color: #000066;">Layer</span>=<span style="color: #ff0000;">&quot;Bottom&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Bottom&quot;</span> <span style="color: #000066;">Position</span>=<span style="color: #ff0000;">&quot;1106;651,96&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeitems<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;Methods&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;OnApplyTemplate&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treeviewitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treeitems<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treeviewshape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewshape</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;bfcbbeef-fa17-4ea5-8f66-32e5aff6572b&quot;</span> <span style="color: #000066;">Size</span>=<span style="color: #ff0000;">&quot;NaN (Niet-een-getal);NaN (Niet-een-getal)&quot;</span> <span style="color: #000066;">Location</span>=<span style="color: #ff0000;">&quot;223;114,04&quot;</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;ActivityBase&quot;</span> <span style="color: #000066;">SubHeader</span>=<span style="color: #ff0000;">&quot;Class&quot;</span> <span style="color: #000066;">SubSubHeader</span>=<span style="color: #ff0000;">&quot;Object&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connector</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;c7c5d368-1773-4267-8f2d-e2f82b42bc29&quot;</span> <span style="color: #000066;">Layer</span>=<span style="color: #ff0000;">&quot;Left&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Left&quot;</span> <span style="color: #000066;">Position</span>=<span style="color: #ff0000;">&quot;224;231,34&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connector</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;45e7cf57-1cc6-4529-a03f-dae3f483b231&quot;</span> <span style="color: #000066;">Layer</span>=<span style="color: #ff0000;">&quot;Top&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Top&quot;</span> <span style="color: #000066;">Position</span>=<span style="color: #ff0000;">&quot;316;115,04&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connector</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;96547264-8961-4909-a4a6-6b5b1c307e6d&quot;</span> <span style="color: #000066;">Layer</span>=<span style="color: #ff0000;">&quot;Right&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Right&quot;</span> <span style="color: #000066;">Position</span>=<span style="color: #ff0000;">&quot;408;231,34&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connector</span> <span style="color: #000066;">UID</span>=<span style="color: #ff0000;">&quot;8162149f-1304-40b9-8b1b-9f94c46f8b42&quot;</span> <span style="color: #000066;">Layer</span>=<span style="color: #ff0000;">&quot;Bottom&quot;</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Bottom&quot;</span> <span style="color: #000066;">Position</span>=<span style="color: #ff0000;">&quot;316;347,64&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeitems<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;Properties&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;Name&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;Enabled&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;StepTime&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;StartTime&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;Duration&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treeviewitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;Methods&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;Run&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;RunAfter&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;treeviewitem</span> <span style="color: #000066;">Header</span>=<span style="color: #ff0000;">&quot;Stop&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treeviewitem<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treeitems<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/treeviewshape<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/shapes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/layer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/layers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/document<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gradium<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</td>
</tr>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://visualizationtools.net/default/creating-class-diagrams-with-g2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple MVC diagramming (in WPF)</title>
		<link>http://visualizationtools.net/default/simple-mvc-diagramming/</link>
		<comments>http://visualizationtools.net/default/simple-mvc-diagramming/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 10:12:19 +0000</pubDate>
		<dc:creator>Francois Vanderseypen</dc:creator>
				<category><![CDATA[Diagramming]]></category>
		<category><![CDATA[G2]]></category>

		<guid isPermaLink="false">http://www.orbifold.net/default/?p=1119</guid>
		<description><![CDATA[On request. An MVC diagramming sample, just the essentials.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.orbifold.net/default/wp-content/uploads/simplemvcdiagramming.png"><img style="margin:12px;" class="size-medium wp-image-1120 alignleft" title="Simple MVCdiagramming" src="/default/wp-content/uploads/simplemvcdiagramming-225x300.png" alt="" width="225" height="300" /></a></p>
<p>After many fan requests I finally took a few hours to cook up a proof-of-concept showing how to construct a MVC decoupling between data storage, logic and presentation. The sample does <strong>not </strong>show:</p>
<ul>
<li>how to use the command pattern and how to implement undo-redo</li>
<li>how to data-bind connections to shapes</li>
<li>how to enable copy/paste</li>
</ul>
<p>On the other hand, I did implement the (de)serialization of the diagram and shapes are templated. This simple bunch of code is the core architecture of how GraphSquare is internally (modulo the omissions I metioned above), all the rest is simply a few thousands hours of work more <img src='http://visualizationtools.net/default/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a href="http://www.orbifold.net/Downloads/SimpleMVC/SimpleMVCDiagramming.zip">Download the sample</a></p>
<p>Note that this sample has been integrated into <a href="/DSK/">the DSK</a> which contains a paradise of diagramming code if you wish to get started in WPF diagramming.</p>
]]></content:encoded>
			<wfw:commentRss>http://visualizationtools.net/default/simple-mvc-diagramming/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GraphSquare architecture IV</title>
		<link>http://visualizationtools.net/default/graphsquare-architecture-iv/</link>
		<comments>http://visualizationtools.net/default/graphsquare-architecture-iv/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 14:59:54 +0000</pubDate>
		<dc:creator>Francois Vanderseypen</dc:creator>
				<category><![CDATA[Diagramming]]></category>
		<category><![CDATA[G2]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.orbifold.net/default/?p=1061</guid>
		<description><![CDATA[This rather long article reviews first the various mechanisms available in .Net to (de)serialize data where after we review the problems and challenges you are faced with when considering (de)serialization in a WPF context and, finally, we explain how we constructed a custom serialization mechanism in GraphSquare.]]></description>
			<content:encoded><![CDATA[<p>In the <a href="/default/wp-admin/post.php?action=edit&#038;post=1059">previous part</a> we talked a bit about tools and surface mechanisms, this time we&#8217;ll talk about the serialization of diagrams, which is a huge topic on its own and a complicated one at times too. You probably know that serialization is related to  copy/paste, saving things to files, the property grid, drag-drop&#8230; In fact serialization is pretty much everywhere: WCF services, Windows workflows, P2P communication and more. The .Net frameworks gives you a wealth of mechanisms to help you serialize things with various levels of sophistication: attributes (Serializable, DataContract,&#8230;), interfaces (ISerializable, IXmlSerializable&#8230;) and formatters (binary, soap, xml&#8230;) together with whole namespaces full of utility classes. In the next few paragraphs I&#8217;ll review first some basics of serialization, explain the internal structure of our (MVC) Model, highlight the problems you encounter when trying to serialize a diagram and, finally, explain the (non-standard) serialization  system of GraphSquare.</p>
<p>
<span id="more-1061"></span>
</p>
<h2>How to serialize stuff in .Net</h2>
<h3>Black-box serialization</h3>
<p>The easiest way to serialize a class in .Net is by decorating a class with the System.Serializable attribute. It tells the CLR to pick up the public and private fields and to save them as part of the data necessary to reconstruct an instance. In case you want to drop a few fields in this process you can use the <a id="ctl00_rs1_mainContentContainer_ctl06" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl06',this);" href="http://msdn.microsoft.com/en-us/library/system.nonserializedattribute%28VS.71%29.aspx">NonSerializedAttribute</a> attribute which will discard the field decorated with this attribute.Note that the NonSerialized attribute cannot be applied on a property but only on a field, the reason escapes me however.</p>
<div class="wp_codebox">
<table>
<tr id="p10614">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
</pre>
</td>
<td class="code" id="p1061code4">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Serializable<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> BlackBox
<span style="color: #008000;">&#123;</span>
<span style="color: #008000;">&#91;</span>NonSerialized<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">object</span> ThisWillNotBeSerialized<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> FirstName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> LastName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Weight <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<h3>The controlled serialization</h3>
<p>If the two attributes above do not give you enough control over the serialization of your class you can go for the handcrafted serialization using the <a title="ISerializable interface" href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializable.aspx" target="_blank">System.Runtime.Serialization.ISerializable </a>interface. This interface has a deceptively simple signature which only requires you to hadn over those objects you want to serialize. The method passes a serialization info object which acts as a string-object dictionary in which you can store whatever you wish, even things non-related to the fields of you class.</p>
<div class="wp_codebox">
<table>
<tr id="p10615">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre>
</td>
<td class="code" id="p1061code5">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Serializable<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> ControlledBlackBox <span style="color: #008000;">:</span> ISerializable
<span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">object</span> ThisWillNotBeSerialized<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> FirstName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> LastName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Weight <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> GetObjectData<span style="color: #008000;">&#40;</span>SerializationInfo info, StreamingContext context<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        info<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FirstName&quot;</span>, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FirstName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        info<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;LastName&quot;</span>, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LastName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        info<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;InFactAnyNameYouWish&quot;</span>, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Weight</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">//non-field related data</span>
        info<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;SomethingYouWantToSave&quot;</span>, <span style="color: #FF0000;">3.141592</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">protected</span> ControlledBlackBox<span style="color: #008000;">&#40;</span>SerializationInfo info, StreamingContext context<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
&nbsp;
        FirstName <span style="color: #008000;">=</span> info<span style="color: #008000;">.</span><span style="color: #0000FF;">GetString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FirstName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        LastName <span style="color: #008000;">=</span> info<span style="color: #008000;">.</span><span style="color: #0000FF;">GetString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;LastName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        Weight <span style="color: #008000;">=</span> info<span style="color: #008000;">.</span><span style="color: #0000FF;">GetInt32</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;InFactAnyNameYouWish&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #6666cc; font-weight: bold;">double</span> pi <span style="color: #008000;">=</span> info<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDouble</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;SomethingYouWantToSave&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p>The interface does not tell you that in order to function well this requires a constructor with the same signature wherein you can pick up the stuff you saved and re-initialize the class with it. Actually, you can store whatever you wish in the serialization info, it does not need to be related to fields of you class. Often you need some ambient information to correctly instantiate an object and this is how you can store additonal data. The AddValue has many overloads and at times it can be difficult to use the correct one (try to (de)serialize an Enum to see what I mean). It&#8217;s also through this AddValue method that you actually chain a serialization process. As soon as you use custom objects as data types in your fields you tell the CLR to serialize this data type as well. The CLR will automatically create internally a graph of those objects to be serialized and by wanting to serialize one class in easily slip in having to serialize a whole bunch of classes in your project.</p>
<div class="wp_codebox">
<table>
<tr id="p10616">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre>
</td>
<td class="code" id="p1061code6">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Serializable<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> ControlledBlackBox <span style="color: #008000;">:</span> ISerializable
<span style="color: #008000;">&#123;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> CustomData ChainedDataMember <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> GetObjectData<span style="color: #008000;">&#40;</span>SerializationInfo info, StreamingContext context<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
info<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ChainedDataMember&quot;</span>, <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ChainedDataMember</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">protected</span> ControlledBlackBox<span style="color: #008000;">&#40;</span>SerializationInfo info, StreamingContext context<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
&nbsp;
ChainedDataMember <span style="color: #008000;">=</span> info<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ChainedDataMember&quot;</span>, <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #008000;">&#40;</span>CustomData<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> CustomData<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#91;</span>Serializable<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> CustomData
<span style="color: #008000;">&#123;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> SomeMoreHere <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<h3>The controlled deserialization with callback</h3>
<p>During serialization the CLR will traverse the serialization graph from top to bottom and you can control everyting using the GetObject method. During deserialization you have an additional interface at your disposal which will be called after all classes in the internal graph have been deserialized. The CLR will call the System.Runtime.Serialization.IDeserializationCallback if implemented in reverse order and it allows you to do some post-deserialization which can be necessary when objects are inter-related.</p>
<div class="wp_codebox">
<table>
<tr id="p10617">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre>
</td>
<td class="code" id="p1061code7">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Serializable<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> SerializationWithCallback <span style="color: #008000;">:</span> ISerializable, IDeserializationCallback
<span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnDeserialization<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//some post-serialization code here</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> GetObjectData<span style="color: #008000;">&#40;</span>SerializationInfo info, StreamingContext context<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<h3>The controlled (de)serialization with pre-post processing</h3>
<p>On top of all this you can complement you (de)serialization process with pre &amp; post (de)serialization methods which will be called directly before respectively after the (de)serialization is applied to your class. There is not conflict with the callback described above since the callback is applied after all classes have been deserialized while the OnDeserialized method is called directly after the class was deserialized. Yet, I admit, it can be quite compelx sometimes to trace down some bugs and to understand what the CLR is doing when it starts to switch between classes and calling recursively all kinds of methods.</p>
<div class="wp_codebox">
<table>
<tr id="p10618">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre>
</td>
<td class="code" id="p1061code8">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Serializable<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> SerializationWithCallbackAndPrePost <span style="color: #008000;">:</span> ISerializable, IDeserializationCallback
<span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnDeserialization<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//some post-serialization code here</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> GetObjectData<span style="color: #008000;">&#40;</span>SerializationInfo info, StreamingContext context<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#91;</span>OnDeserialized<span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnDeserialized<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
       <span style="color: #008080; font-style: italic;">//called just after the class was deserialized</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#91;</span>OnDeserializing<span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnDeserializing<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #008080; font-style: italic;">//called just before the CLR enters the deserialization of this class</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#91;</span>OnSerialized<span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnSerialized<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #008080; font-style: italic;">//called just after the CLR serialized this class</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#91;</span>OnSerializing<span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnSerializing<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #008080; font-style: italic;">//called just before the CLR enters the serialization of this class</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p>Be aware that all this goodness gives you a lot of power but as with every big power, you need to understand in details what is going on in order to use it effectively or you easily end up with a spaghetti of &#8216;goto&#8217; effects in you code.</p>
<h3>Xml serialization</h3>
<p>Besides the binary serialization we have described above you have also an whole set of possibilities to (de)serialize things to XML (and SOAP in particular). From my point of view this whole machinery has become somewhat obsolete since the introduction of LINQ to XML where I think things are much easier to manipulate, but we&#8217;ll quickly review things here.</p>
<p>Here again you can either rely on a black-box XML serialization by simply passing you type to the XmlSerializer method or you can fine-tune the process by means of attributes.</p>
<div class="wp_codebox">
<table>
<tr id="p10619">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre>
</td>
<td class="code" id="p1061code9">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>XmlRoot<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;RootName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> SimpleXmlSerialization
<span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#91;</span>XmlElement<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;TheFirstName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> FirstName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#91;</span>XmlIgnore<span style="color: #008000;">&#93;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> NameValueCollection Attributes
  <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> _attributes<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    set <span style="color: #008000;">&#123;</span> _attributes <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> YourMainCode
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> SerializeToXml<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
&nbsp;
        SimpleXmlSerialization obj <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SimpleXmlSerialization <span style="color: #008000;">&#123;</span>FirstName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Just me&quot;</span><span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
        XmlSerializer serializer <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> XmlSerializer<span style="color: #008000;">&#40;</span>obj<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        Stream stream <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FileStream<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;c:<span style="color: #008080; font-weight: bold;">\\</span>MyFile.xml&quot;</span>, FileMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span>,
               FileAccess<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span>, FileShare<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        serializer<span style="color: #008000;">.</span><span style="color: #0000FF;">Serialize</span><span style="color: #008000;">&#40;</span>stream, obj<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        stream<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p>To gain more control on this process you can implement the IXmlSerializable interface which allows you to actually control completely what will be written to disk:</p>
<div class="wp_codebox">
<table>
<tr id="p106110">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre>
</td>
<td class="code" id="p1061code10">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Serializable<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> XMLControlledBox <span style="color: #008000;">:</span> IXmlSerializable
<span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Schema</span><span style="color: #008000;">.</span><span style="color: #0000FF;">XmlSchema</span> GetSchema<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> ReadXml<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">XmlReader</span> reader<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> WriteXml<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">XmlWriter</span> writer<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p>It&#8217;s precisely in this context (in the WriteXml and ReadXml) that I believe you can actually nowadays  better rely on the LINQ to XML than to fiddle with the System.Xml.XmlWriter class.</p>
<p>You will also find in the System.Runtime.Serialization.Formatters namespace (you&#8217;ll need to reference the associated equally-named assembly in order to access it) the SOAP formatter which allows you to (de)serialize things using a SOAP envelope which can be used in peculiar (webservice related) situations.</p>
<p>In the context of WPF and somewhat related to XML you can also find in the System.Windows.Markup namespace the <a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlwriter.aspx">XAMLWriter </a>class which exports any WPF construct to XAML markup. We will come back to this below.</p>
<h2>Diagramming and (de)serialization</h2>
<h3>Debugging complexity</h3>
<p>In general, serializing simple things is simple and serializing complicated things is, well, complicated. In most cases you can get away with the black-box serialization by simply decorating a class with the [Serializable] attribute, which is based on the properties and the default constructor. This works well for standard data types and not too complicated hierarchies of classes. Indeed, as soon as you decorate a class with the serialization attribute the CLR will create internally a graph of objects which has to be serialized. If you have a complex inheritance system and many custom data types you quicly get a huge set of classes you are forced to decorate too and eventually end up with serialization loops: two classes referencing each other by means of properties will create loops in the serialization graph and you will get exceptions at runtime. Not at compile time but at runtime. Even with all the pre/post attributes and callbacks at your disposal things easily get horrendously difficult to trace when your Visual Studio debugger starts to jump between (de)serialization methods, pre-post methods and callbacks.</p>
<h3>No control over the (de)serialization sequence</h3>
<p>The custom serialization gives you a grip on the serialization process on the class level but not on the hierarchy level. By this I mean that you can control how and what will be (de)serialized on a class level but you have no control over the order the CLR accesses the various classes in your object hierarchy. In order to explain this more in details I&#8217;ll have to explain first the way that one usually starts a serialization process.</p>
<p>If you want to serialize some stuff to binary format you&#8217;ll scribble something down like the following:</p>
<div class="wp_codebox">
<table>
<tr id="p106111">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
</pre>
</td>
<td class="code" id="p1061code11">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Serialize<span style="color: #008000;">&#40;</span>DocumentWrapper wrapper<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    BinaryFormatter binFormat <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> BinaryFormatter<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>Stream fStream <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FileStream<span style="color: #008000;">&#40;</span>FileName, FileMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span>, FileAccess<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span>, FileShare<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        binFormat<span style="color: #008000;">.</span><span style="color: #0000FF;">Serialize</span><span style="color: #008000;">&#40;</span>fStream, wrapper<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p>where the &#8216;wrapper&#8217; is the stuff you want to save to disk. The serialize method of the binary formatter will first create and object graph on the basis of the wrapper object by looking at either the properties (in the case of black-box serialization) or by recursively calling the ISerializable method in the order that you added object to the serialization info dictionary. In general this works well but not for the serialization of diagrams. The problem being the fact that you cannot serialize bindings of objects and this is precisely the case with diagram connections between diagram nodes. The issue is rather technical but it all amounts to two different tensions: on the one hand the order of things to serialize and on the other the inter-dependency of objects in a diagram. The situation is really rather unusual in the sense that most line of business applications have a tree-like data dependency while diagram data is inherently graph-like (non-linear, that is). The situation is aggravated by the inverse problem when you deserialize a diagram, even with all these techniques described above you will discover that deserialization of diagrams is a complicated affair.</p>
<h3>Strong coupling with WPF, import, export, WCF and more</h3>
<p>If you present something like a &#8216;shape&#8217; in a diagram you inevitably have somewhere a class which inherits from a WPF base class like the ContentControl. This makes your Model WPF dependent but worse, it brings along a whole bunch of stuff you have no control over. Imagine you wish to re-use the Model underneath a WCF service and create diagrams outside the WPF surface, you will be forced to reference WPF assemblies where they don&#8217;t make much sense. In addition, you will run into troubles when having to rely on style and template resources (XAML) which will not be actually applied unless you internally create a surface (something like a Canvas).</p>
<p>Consider also the need for importing diagrams from standard XML, say you want to display any type of XML in a tree diagram. Do you actually want to expose the internals of your Model to the outside world? One of the ideas I had while creating the whole architecture was to be able to have a provider pattern underneath the diagram repository. Because one cannot envisage all possible data scenarios it&#8217;s a good idea to create an open end where others can plug into. For example, how to enable one to create a data connection to a custom database? That is, storing diagrammatic information in some database and, conversely, importing data from external systems. What about creating mashups with webservices like Facebook or MySpace?</p>
<p>Last but not least, one of the most powerful aspects of WPF is data binding. However, data binding cannot be (de)serialized in a snap, which both handicaps the standard mechanisms and also requires extra efforts from your side.</p>
<h3>Code doubling and decentralization of diagram manipulation code</h3>
<p>Deserialization on the basis of the standard .Net mechanisms doubles your code which relates to your model. On the one hand you have inside the command units (the classes which are part of the undo-redo system) some code which accesses methods of your controller or model, things like AddShape, AddPage and so on. On the other hand, the deserialization is constructing shapes and pages without making use of these methods. Indeed, it would make little sense to call an AddShape method inside the deserialization constructor since this would create a recusive stack. So, if you change something in your AddShape method you have to make sure that this addition is also reflected in your deserialization and vice versa. Note also that calling the undo-redo commands in your deserialization is not an option. Opening and saving stuff is never an undo-able action.</p>
<p>Wouldn&#8217;t it be better to have a centralized diagram methods which are used whether the origin is deserialization, import, originating from a webservice call or a user interactions on the surface?</p>
<h3>The conclusion</h3>
<p>After many experiments, trials and frustration it became obvious (to me) that instead of relying on the internal process of the CLR it was necessary to create a custom serialization which would</p>
<ul>
<li>give complete control over the way that the Model was being serialized</li>
<li>enable to use the diagrammatic methods (like AddShape, AddPage and son on) rather than the instantiation of classes which required complicated pre- and post-processing</li>
<li>decouple the WPF dependency and in fact enable a client-independent Model and serialization</li>
<li>eventually lead to more work but would ease the debugging considerably</li>
<li>enable unit-tests and have a fine-grained control over all aspects of everything related to data import, export and (de)serialization</li>
</ul>
<h2>Data exchange in GraphSquare</h2>
<p>In the next few paragraphs I&#8217;ll highlight how the (de)serialization was constructed in GraphSquare but I&#8217;d like to emphasize again that you should carefully consider your options in your own project because in general you don&#8217;t need the high-tech stuff we have implemented. I think as a data structure a diagram is rather peculiar and, in fact, the most generic type of data hierarchy you can imagine: blobs of data bound in an arbitrary way to each other. Usually you&#8217;ll find in your own to-be-serialized data structures some kind of symmetry or pattern which allows you to simplify the serialization considerably.</p>
<p>Before continuing, let me mention or recall the following:</p>
<ul>
<li>there is a <a title="XAMLWriter" href="http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlwriter.aspx" target="_blank">XAMLWriter </a>class which provides a single static <a id="ctl00_rs1_mainContentContainer_ctl02" title="The Save() method" onclick="javascript:Track('ctl00_rs1_mainContentContainer_ctl00|ctl00_rs1_mainContentContainer_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/system.windows.markup.xamlwriter.save.aspx" target="_blank">Save</a> method that can be used for limited Extensible Application Markup Language (XAML) serialization of provided runtime objects into XAML. This class provides an additional black-box serialization method in the context of WPF, see however <a title="Some limitations" href="http://msdn.microsoft.com/en-us/library/ms754193.aspx" target="_blank">its limitations</a>. The advice here is to experiment and see if this suits your needs. It basically implements the XML serialization of .Net</li>
<li>you cannot serialize data bindings without extra efforts, don&#8217;t expect binding to magically re-appear after deserialization. If you have bindings you&#8217;ll need either to serialize in some way or hard-code it in your deserialization system.</li>
<li>the templating system of WPF can be at times an horrendous obstacle. The reason is that a template and the loading of the elements defined in it are only applied when the control is effectively visible in the interface. Imagine you have (as it is in our GraphSquare case) connectors defined in a template, how to deserialize connections bound to connectors if these will only be available when the connection has been already added to the surface? There is an ApplyTemplate() method defined in the FrameworkElement class but it does not always bypass the problem. This template issue creates an additional ordering problem (besides the two ordering problems I alluded above) when you (de)serailize a diagram.</li>
<li>the resources (i.e. styles, templates&#8230;) of WPF are unavailable if you use unit tests which blocks the debugging of (de)serialization through unit tests. As far as I know there is no solution to this.</li>
</ul>
<h3>The document hierarchy</h3>
<p>Before explaining the actual serialization code let me highlight the internal structure of the model. The MVC-model is actually called the &#8216;Document&#8217; and can be considered as the database of the diagram. The Document contains all the info and its hierarchy reflects the way that the diagram control presents itself to the user. For example, the layers are sub-ordinate to the page and shapes are part of a layer.</p>
<p><img style="float:left;clear:right;margin:5px;" title="document hierarchy" src="http://www.orbifold.net/default/wp-content/uploads/documenthierarchy.png" alt="" width="255" height="336" /></p>
<p>The <strong>Document </strong>is the root of the hierarchy is in fact the same as the <strong>Model </strong>in the MVC pattern. It&#8217;s the data repository of the whole system and contains all members which alters the diagram and the control. The surface members are aliases to the Controller which delegates things down to the Document. The alterations are propagated back to the surface through events which are picked up by the controller and sub-sequentially by the surface.</p>
<p>The <strong>metadata </strong>is a small class wherein things like author and creation date are recorded.</p>
<p>The <strong>page collection</strong> contains all the pages of the diagram control and each page contains info like background color, layout type, page title and so on.</p>
<p>The <strong>layer collection</strong> contains the layers per page. Some page types do not accept multiple layers, like the mindmapping type where a layer is conceptually similar to collapsing branches.</p>
<p>A layer contains <strong>shapes </strong>and <strong>connections </strong>as separate collection even though each connector in a shape has the information about the connections. One could put the connection collection hierarchically underneath the connector but in practice it makes life easier to have it like this in function of (de)serialization.</p>
<p>An important note here is that the binding between shape and <strong>connector </strong>is loose in the sense that the connector collection is not part of the shape definition but defined in the template applied to the shape. This makes things more complicated for the (de)serialization but allows a certain flexibility in defining and customizing shapes.</p>
<h3>The data abstraction and data adapters</h3>
<p>The data abstraction layer consist of surrogate classes which can be compared with data entities in multi-tiered database application. They encapsulate the essence of a diagram entity (connector, shape, page&#8230;) without any reference to WPF or anything. Obviously you need to store in them a reference to the name of a template or style if you wish to show them on a UI/WPF surface but this does not enforce anything. In fact, using our abstraction layer one can create diagrams in totally non-WPF environments like underneath a WCF service, using database inserts or through standard WinForms (propertygrid). Unity is also playing a big role in this mechanism, because at some point you need to convert a surrogate entity to an actual Document entity. The decoupling allows one to perform this conversion inside a Unity container and in this way to achieve a certain independence, that is the container injects some objects which are allowed to be assigned on the basis of a common interface.</p>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/presystem.png"><img class="aligncenter size-full wp-image-1063" title="Surrogate wrapper" src="http://www.orbifold.net/default/wp-content/uploads/presystem.png" alt="" width="822" height="331" /></a></p>
<p>For each concrete diagram class one has a surrogate class which we prefixed with &#8216;Pre&#8217; (what&#8217;s in a name obviously?) and they are bound to each other by means of reciprocal methods called GetShape and Wrap. When a data exchange process is started the surrgate DocumentWrapper will be handed over and it allows a data adpater to serialize it in some way. Conversely, when a data adapter loads serialized data it hands over a DocumentWrapper to the core, i.e. the Document. In this sense, the data abstraction layer consists of a single class, the DocumentWrapper, through which all data exchange occurs. From the point of view of the Document the origin of the DocumentWrapper is unknown. From the point of view of the external provider the DocumentWrapper is unrelated to WPF and the Document. As much as data entities in a N-tier database application form the intermediate step to business entities, so are the surrogate entities intermediate to the actual shapes in the Document (Model).</p>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/dataexpimp.png"><img class="alignright size-full wp-image-1064" title="Import export" src="http://www.orbifold.net/default/wp-content/uploads/dataexpimp.png" alt="" width="500" height="336" /></a></p>
<p>When the controller starts an exchange process it needs to provide a data adapter and all the rest occurs inside the adapter. The adapter accesses the DocumentWrapper and turns whatever it wishes into whatever format. For example, the XML adapter uses LINQ to XML to turn all the surrogate classes into XML elements. Conversely, we have a generic XML adapter which takes any incoming XML and turns it into a default DocumentWrapper. The adapter (or provider model if you prefer) is generic and can be implement externally. In order to add it to the control we make use of the Unity application block.</p>
<p>Coming back to the problems mentioned above, in the process of building the DocumentWrapper we implement our own to-be-serialized graph of surrogate classes. While this might sound complicated it really amounts just to some for-each loops on the pages, layers and other collections. Conversely, in order to convert a DocumentWrapper to an actual Document we control every step whereby we make use of the AddShape, AddPagee&#8230;methods of the Document to build up the diagram. This then is probably the crucial point; we don&#8217;t use serialization constructor but rather the standard Document methods to deserialize a diagram. In this sense, the whole logic remains centralized in these methods: data binding, event binding and so on. In order not to cause an avalange of events if the diagram control is embedded we have a global event-blocking property, but this can be switched off if necessary.</p>
<p>Obviously, the description here is rather schematic and a whole lot of code (over 2000 lines in fact) is required to make all this really functional. The details will not be published or released but I&#8217;d hope that this article clears the sky a bit for those who are looking for a robust serialization architecture.</p>
<p>In the next part we&#8217;ll have a look at something more fun and simple; WPF styling, triggers, animation and such.</p>
]]></content:encoded>
			<wfw:commentRss>http://visualizationtools.net/default/graphsquare-architecture-iv/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GraphSquare architecture III</title>
		<link>http://visualizationtools.net/default/graphsquare-architecture-iii/</link>
		<comments>http://visualizationtools.net/default/graphsquare-architecture-iii/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 05:28:27 +0000</pubDate>
		<dc:creator>Francois Vanderseypen</dc:creator>
				<category><![CDATA[Diagramming]]></category>
		<category><![CDATA[G2]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.orbifold.net/default/?p=1059</guid>
		<description><![CDATA[On the implementation of 'tools' in the MVC View.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.orbifold.net/default/wp-content/uploads/itool.jpg"><img style="float:left;clear:right;margin:10px;" title="Tool interface" src="http://www.orbifold.net/default/wp-content/uploads/itool.jpg" alt="" width="417" height="238" /></a>In <a href="http://www.orbifold.net/default/?p=1055">the previous part</a> we looked at the MVC core, this time we&#8217;ll highlight the ideas and the code related to &#8216;tools&#8217;. <strong>A tool is basically a series of actions the user performs and which results in a command on the undo-stack.</strong> For example:</p>
<ul>
<li>selecting some shapes with the typical rubberband is a tool, the series of actions being related to the mouse down, mouse move and mouse up events.</li>
<li>scaling or rotating a shape, which involves the adorners and the mouse events</li>
<li>creating a connection</li>
</ul>
<p>and so on. The abstract tool concept originates from the fact that if you don&#8217;t package a series of actions in a separate class you inevitably have a complex logical flow in the overriden mouse-methods of the surface. So, instead of having various if-then-else statements in the MouseDown, MouseMove and MouseUp handlers you simply loop over all registered tools and whichever tool is &#8216;on&#8217; can react accordingly. This approach has the additional advantage that you can</p>
<ul>
<li>add tools with ease</li>
<li>disable or overrule other tools in the loop</li>
<li>chain tools, if necessary</li>
</ul>
<p> Below is a snippet of the mouse handlers which are called by the surface corresponding to the mouse events on this surface. Note that the loop in these handlers are broken as soon as one of the tools have opted to handle the event.</p>
</p>
<div class="wp_codebox">
<table>
<tr id="p105912">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre>
</td>
<td class="code" id="p1059code12">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> MouseDown<span style="color: #008000;">&#40;</span>MouseEventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
&nbsp;
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>ITool tool <span style="color: #0600FF; font-weight: bold;">in</span> toolList<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>tool <a href="http://www.google.com/search?q=is+msdn.microsoft.com"><span style="color: #008000;">is</span></a> Core<span style="color: #008000;">.</span><span style="color: #0000FF;">IMouseListener</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>tool <span style="color: #0600FF; font-weight: bold;">as</span> Core<span style="color: #008000;">.</span><span style="color: #0000FF;">IMouseListener</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MouseDown</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> MouseMove<span style="color: #008000;">&#40;</span>MouseEventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>ITool tool <span style="color: #0600FF; font-weight: bold;">in</span> toolList<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>tool <a href="http://www.google.com/search?q=is+msdn.microsoft.com"><span style="color: #008000;">is</span></a> Core<span style="color: #008000;">.</span><span style="color: #0000FF;">IMouseListener</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>tool <span style="color: #0600FF; font-weight: bold;">as</span> Core<span style="color: #008000;">.</span><span style="color: #0000FF;">IMouseListener</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MouseMove</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> MouseUp<span style="color: #008000;">&#40;</span>MouseEventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>ITool tool <span style="color: #0600FF; font-weight: bold;">in</span> toolList<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>tool <a href="http://www.google.com/search?q=is+msdn.microsoft.com"><span style="color: #008000;">is</span></a> Core<span style="color: #008000;">.</span><span style="color: #0000FF;">IMouseListener</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>tool <span style="color: #0600FF; font-weight: bold;">as</span> Core<span style="color: #008000;">.</span><span style="color: #0000FF;">IMouseListener</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MouseUp</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p>Most of the tools have some kind of visual feedback, on creating a rectangle you would see for example a rubberband which previews the end-result. For this purpose a few classes are necessray which specializes the ITool interface (depicted above) and all tools which need a rubberband are inheriting from it. The whole rubberband (sometimes called &#8216;marching ants&#8217;) affair is also taken separately in other constructs (a static helper class) and the process of creating tools becomes in the end a game of putting some blocks together. In fact, a dummy tool with visual feedback would look something like this:</p>
<div class="wp_codebox">
<table>
<tr id="p105913">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre>
</td>
<td class="code" id="p1059code13">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> DummyTool <span style="color: #008000;">:</span> RubberCreationToolBase
<span style="color: #008000;">&#123;</span>
&nbsp;
&nbsp;
    <span style="color: #008080;">#region Constructor</span>
    <span style="color: #008080; font-style: italic;">///&lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">///Default constructor</span>
    <span style="color: #008080; font-style: italic;">///&lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> DummyTool<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">:</span><span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Dummy Tool&quot;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
    <span style="color: #008080;">#endregion</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnExecute<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Windows</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Input</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ExecutedRoutedEventArgs</span> e<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        GhostManager<span style="color: #008000;">.</span><span style="color: #0000FF;">Surface</span> <span style="color: #008000;">=</span> sender <span style="color: #0600FF; font-weight: bold;">as</span> DiagramSurface<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnExecute</span><span style="color: #008000;">&#40;</span>sender, e<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> DrawGhost<span style="color: #008000;">&#40;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Windows</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Rect</span> rec<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        GhostManager<span style="color: #008000;">.</span><span style="color: #0000FF;">DrawRectangularGhost</span><span style="color: #008000;">&#40;</span>rec<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnRubberCreated<span style="color: #008000;">&#40;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Windows</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Rect</span> rec<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Surface<span style="color: #008000;">.</span><span style="color: #0000FF;">Controller</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Output</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;The '&quot;</span> <span style="color: #008000;">+</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;' tool finished but no realshape was added.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p>The overridable DrawGhost method allows you to give whatever feedback you wish while the overridable OnRubberCreated allows you to do whatever you wish after the rubber was creates, i.e. after the user released the mouse.  It&#8217;s precisely in this method that one should package the action (say, the creation of a shape) in a command and push it onto the undo-stack. In the dummy tool above only an informative message is displayed.</p>
<p>Of course, in order to manage the available tools and to connect them to the UI you need some more code in the form of some tool manager. The tool manager is just a wrapped generic list created through Unity inside the surface class. Note, in this context, that the concept of a tool only makes sense on the UI level and is, hence, not re-usable in other surfaces (e.g. a web-interface).</p>
<p>In the next part we&#8217;ll discuss the other end of the architecture; data abstraction and the serialization of diagrams.</p>
]]></content:encoded>
			<wfw:commentRss>http://visualizationtools.net/default/graphsquare-architecture-iii/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GraphSquare architecture II</title>
		<link>http://visualizationtools.net/default/graphsquare-architecture-ii/</link>
		<comments>http://visualizationtools.net/default/graphsquare-architecture-ii/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 11:45:12 +0000</pubDate>
		<dc:creator>Francois Vanderseypen</dc:creator>
				<category><![CDATA[G2]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Diagramming]]></category>

		<guid isPermaLink="false">http://www.orbifold.net/default/?p=1055</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>In this second part we will describe in some details the MVC core of GraphSquare (G2). See <a href="http://www.orbifold.net/default/?p=1053">Part I</a> for the intro and a feature overview.</p>
<p style="text-align: center;"><a href="http://www.orbifold.net/default/wp-content/uploads/architecture2.jpg"><img class="alignnone size-full wp-image-1056" title="The MVC core" src="http://www.orbifold.net/default/wp-content/uploads/architecture2.jpg" alt="" /></a></p>
<h1>The surface (or View)</h1>
<p>The surface holds and presents the <a title="UIElement class" href="msdn.microsoft.com/en-us/library/system.windows.uielement.aspx" target="_blank">UIElement </a>by means of an inherited <a title="The Canvas class" onclick="urchinTracker('/outgoing/msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx?referer=');urchinTracker('/outgoing/msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx?referer=');urchinTracker('/outgoing/msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx?referer=');" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx" target="_blank">Canvas</a>. All diagram elements inherit (sometimes through a long chain) from the Control class, but we will describe later on the hierarchy behind shapes and diagram elements.</p>
<p>The surface is a rather &#8216;dumb&#8217; piece in the sense that it&#8217;s mostly a sink for all actions from the user and a drain for all things coming from the controller:</p>
<ul>
<li>it presents a variety of <strong>routed commands</strong> which allows one to attach buttons and other UI element to act upon the diagram</li>
<li>it offers <strong>a lot of events</strong> one can hook on to (OnShapeAdded, OnPageAdded, OnLayerRemoved&#8230;)</li>
<li>it <strong>listens to mouse events</strong> and pass them on to the Controller</li>
<li>it <strong>hosts the various tools</strong> (selection tool, rotate tool&#8230;) which only have a meaning on the surface level: the controller doesn&#8217;t know about &#8216;tools&#8217;, much less the Model</li>
<li>it enables <strong>zooming, panning and scrolling </strong>of the diagram (which is really easy in WPF)</li>
<li>it presents all the <strong>methods </strong>you need to manipulate, edit and create diagrams (and all its organizing elements like layers, pages, groups) by means of code</li>
</ul>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/diagramapi.jpg"><img style="float:left; clear:right; margin:5px;" title="Snapshot of the diagramming API" src="http://www.orbifold.net/default/wp-content/uploads/diagramapi-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>The surface is, hence, just a facade to the outside world and this is precisely why one can replace it with Silverlight or a web-based interface. You can replace here the word &#8216;facade&#8217; with API if you prefer since the collection of event, proprerties and methods available on the diagram control really represent the programming interface to the diagram the control).</p>
<p>One important piece on top of the list is, however, the <strong>presentation factory</strong>. The controller and the model are unaware of the layout algorithm and simply hold the raw data of the shape. When a shape (or diagram element in general) is added to the diagram it really starts in the Document and bubbles up to the surface. This occurs by means of standard chained events and this chain end at the surface where either the diagram element is added &#8216;as is&#8217; or handed over to the presentation factory:</p>
<div class="wp_codebox">
<table>
<tr id="p105514">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
</pre>
</td>
<td class="code" id="p1055code14">
<pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">void</span> Controller_OnDiagramElementAdded<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, DiagramEntityArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">Entity</span> <a href="http://www.google.com/search?q=is+msdn.microsoft.com"><span style="color: #008000;">is</span></a> ILayoutShape<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        presentationFactory<span style="color: #008000;">.</span><span style="color: #0000FF;">Present</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">Entity</span> <span style="color: #0600FF; font-weight: bold;">as</span> ITreeShape<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">Entity</span> <a href="http://www.google.com/search?q=is+msdn.microsoft.com"><span style="color: #008000;">is</span></a> UIElement<span style="color: #008000;">&#41;</span>
        <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">Entity</span> <span style="color: #0600FF; font-weight: bold;">as</span> UIElement<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p style="text-align: center;"><a href="http://www.orbifold.net/default/wp-content/uploads/bubblingevents.jpg"><img style="float:left; clear:right; margin:5px;" title="Bubbling events from the controller" src="http://www.orbifold.net/default/wp-content/uploads/bubblingevents-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>For example, the standard diagram (we call it a &#8216;Concept map&#8217;) doesn&#8217;t need extra presentation processing while a mindmap uses the presentation factory to lay shapes in the well-known fashion. The presentation factory is responsible for the layout and this is the place where one can either use the wonderful possibilities of WPF or rely on precise positioning of elements on the Canvas. We have even gone a step beyond this and use the presentation factory to convert shapes on the fly and sometimes &#8216;wrap&#8217; shapes in containers, which e.g. makes it possible to have <strong>grouping </strong>or sub-structures which not necessarily have a meaning on the controller or model level.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span id="more-1055"></span></p>
<h1>The Controller</h1>
<p>The controller, well, controls the interactions and acts as a switchboard between the model and the surface. One might wonder why it is useful to separate the code into a controller and not keep it in the view. The reason is that this</p>
<ul>
<li>enables the re-use of the controller with a different view, i.e. makes a lot of the code view-independent</li>
<li>does not force one to override or carry the inherited methods which the Canvas (or whatever base surface class) brings along</li>
</ul>
<p>This decoupling comes with a penalty; you need to write extra code to marshall objects from the controller to the surface and vice versa. We have used standard events to couple the different layer together (as can be see in the screenshot above of the bubbled events from the controller to the surface).</p>
<p>The controller receives changes from the surface mainly through three channels:</p>
<ul>
<li>by means of mouse actions (OnMouseUp)</li>
<li>by means of tools (a selection process)</li>
<li>by means of API calls (AddShape())</li>
</ul>
<p>Whatever the channels, the end result is always the encapsulation of some change(s) in either an undo-redo unit or the preparation before being delegated to a lower service, like e.g. the serialization of the diagram. So, the controller can be seen as a packaging engine for the command patternor a preparative switchboard for other services.</p>
<p>Either there a change in the diagram or some other action is performed. If the change affects the diagram (or the organization of it) this has an effect on the Document, otherwise the action is delegated. Serialization or data export are not considered as undoable action and, hence, only those action affecting the Document are recorded in the undo stack.</p>
<p>As is highlighted in the diagram above, the controller makes use of the Unity (injection) container(s) to access diverse services, which can be replaced by custom services if necessary.</p>
<p>From the point of view of the controller:</p>
<ul>
<li>the surface is an &#8216;unknow&#8217; layer where events are passed to and where eventually Document objects (layers, shapes&#8230;) are being presented</li>
<li>the Document is a repository where things bubble up from or are delivered to</li>
</ul>
<p>From the point of view of the surface the controller is where all actions are being delegated to. In fact, most methods on the surface resemble the follow snippet:</p>
<div class="wp_codebox">
<table>
<tr id="p105515">
<td class="line_numbers">
<pre>1
2
3
4
</pre>
</td>
<td class="code" id="p1055code15">
<pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> IShape AddShape<span style="color: #008000;">&#40;</span>Point location, <span style="color: #6666cc; font-weight: bold;">object</span> content, LayerBase layer, PageBase page<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> Controller<span style="color: #008000;">.</span><span style="color: #0000FF;">AddShape</span><span style="color: #008000;">&#40;</span>location, content, layer, page<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p>while things bubbling from the Document are usually simply passed on to the surface as in the prototype below:</p>
<div class="wp_codebox">
<table>
<tr id="p105516">
<td class="line_numbers">
<pre>1
2
3
4
</pre>
</td>
<td class="code" id="p1055code16">
<pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">void</span> document_OnPageAdded<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, PageArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    RaiseOnPageAdded<span style="color: #008000;">&#40;</span>e<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p>Note that through this decoupling we were able to unit-test all interactions without having to rely on UI-automation.</p>
<h1>The Document (or Model)</h1>
<p>The Document is where the diagram and its hierarchy is stored and where all changes propagate from. For example, if on the surface a new shape is added:</p>
<ul>
<li>this action will be first packaged by means of the controller to an undoable unit</li>
<li>the unit will be executed and an AddShape method will be called on the Document</li>
<li>the document will create the new shape and will allocate it</li>
<li>by allocating it a post-creation process will be started which binds events, dresses the shape (templating), binds it to the layer and so on</li>
<li>the OnShapeAdded event will be raised and it will propagate up to the surface where either it&#8217;s presented by adding it via the Canvas.Children.Add() method or there is a presentation process which will lay it out before adding it to the canvas as a child</li>
</ul>
<p>So, the Document contains the actual information while the controller contains the actual &#8216;logic&#8217;. From the point of view of the Document the controller is simply an instance which passes the info on upwards.</p>
<p>Before WPF it would have been possible to abstract away all UI dependence. Because of the templating mechanism and for other reasons the elements of the Document are not completely WPF independent and, hence, not UI independent. This has been handled by adding an additional layer of abstraction which was also necessary for the serialization of the diagram (the Document, that is). We will delve deeper into this when we present the serialization and import/export of the diagram.</p>
]]></content:encoded>
			<wfw:commentRss>http://visualizationtools.net/default/graphsquare-architecture-ii/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>GraphSquare architecture I</title>
		<link>http://visualizationtools.net/default/graphsquare-architecture-i/</link>
		<comments>http://visualizationtools.net/default/graphsquare-architecture-i/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 11:45:00 +0000</pubDate>
		<dc:creator>Francois Vanderseypen</dc:creator>
				<category><![CDATA[Diagramming]]></category>
		<category><![CDATA[G2]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.orbifold.net/default/?p=1053</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>This series intends to give you an overview of GraphSquare&#8217;s internals. It will not teach you how to create from scratch a diagramming control (you can find this elsewhere) but highlights the essential ingredients we used in building a high-end diagramming library. GraphSquare is indeed more <strong>a WPF diagramming framework</strong> than a closed, single-purpose graph control, much less an application although we have built a full diagramming application on top of it.</p>
<p>Before guiding you in all the abstract concepts let me summarize the features of GraphSquare (abbreviated: G2):</p>
<ul>
<li>a WPF diagramming control which can be hosted in any WPF or WinForm application</li>
<li>a model-view-controller (MVC) architecture which can be used seperately: we have used the model, for example, independently in Silverlight and WCF without having to include the view and the controller</li>
<li>a plugable system based on Unity which allows you to replace whole parts of the system: you can register custom implementations of, say, the undo or selection service without recompiling the control</li>
<li>traditional layout algorithms (tree, circular, mindmap&#8230;) which are decoupled from the view through a presentation factory and which, here again, allows you to manipulate the layout outside the compiled code. In particular, the mindmap and tree layouts are completely built based on WPF&#8217;s templating system and, hence, amounts to restyling some XAML</li>
<li>undo-redo through a classic command pattern on the controller level</li>
<li>a provider (adapter) based serialization system which can also be extended through Unity. Out of the box we have built binary, XML and a WCF adapter to import/export data.</li>
<li>an event-based decoupling of the MVC which enables you to connect to, for example, over twenty events on the model to react according to you needs on an application level</li>
<li>a data-flow mechanismÂ  (engine) built into the architecture which allows HMI and other data simulation diagramming interfaces</li>
<li>design-time support for Visual Studio and Expression Blend</li>
<li>fully coded on .Net 3.5 (no interop or Win32 code)</li>
<li>multi-page support: you can have multiple pages per control much like one has multiple sheets in Excel. Each page can have a separate layout algorithm, a separate set of layers and a custom theme.</li>
<li>multi-layer support: inside a page you can organize shapes in layers which can be manipulated independently (transparency, visibility and so on)</li>
<li>custom themes, styles, templates and the wealth of WPF features are at your disposal to customize shapes and connections</li>
<li>custom shapes for specific purposes: the class shape (UML-like shapes), collapsible shapes (with WPF animations)&#8230;</li>
<li>autoconnect shapes, drag-dop support for various data types, zooming, panning, thumbnail view of the diagram&#8230;and many more features you can expect of a high-end diagramming library</li>
</ul>
<p><span id="more-1053"></span></p>
<p>We will move through the architecture in a top-down approach and start with the main lines and refine as we move down. The intention is to cover more-or-less the following topics:</p>
<ul>
<li>The MVC architecture: how the model, the view, the presenter and the controller work together to organize the diagram together with many classes and interfaces.</li>
<li>Presentation decoupling and layout: how the layout is achieved without affecting the underlying Model</li>
<li>Serialization, XML and the data abstraction layer: how we abstracted away the WPF stuff to remain with just the raw data for serialization purposes and data exchange in general.</li>
<li>Styles, themes, templates: how the WPF presentation is used in G2.</li>
<li>Testing and unit testing: how we thoroughly tested the architecture.</li>
<li>Tree diagrams,Concept maps, mindmapping: how the particular layout schemes can be used. We&#8217;ll give an overview of the samples we created.</li>
<li>Server side diagramming and WCF: how the G2-server was built.</li>
<li>A proof of concept: Silverlight. This is to highlight the fact that G2 can be used with Silverlight and, in fact, any type of presentation layer.</li>
<li>Independence through Unity: how Unity articulates extensibility and unifies the decoupling of classes.</li>
<li>Tools for the surface: the tool-mechanism or how you can allow the end-user to create things, pass it to undoredo and manipulate the Model.</li>
<li>Shapes, connections, connectors and the object model: everything about diagram entities and how the visuals are connected in an object model.</li>
<li>The data-flow engine: how we implemented the data-flow mechanism inside the control.</li>
<li>Design-time support: not specific for a diagramming control but merely an overview of the new design-time paradigm Microsoft introduced.</li>
<li>Animations and other WPF specifics: about tangentially related topics.</li>
</ul>
<p>The diagram below should be kept in mind as we move along, it schematically depicts the essential blocks of what we will cover.</p>
<p style="text-align: center;"><a href="http://www.orbifold.net/default/wp-content/uploads/architecture1.jpg"><img class="alignnone size-full wp-image-1054 aligncenter" title="The big overview" src="http://www.orbifold.net/default/wp-content/uploads/architecture1.jpg" alt="" width="500" height="241" /></a></p>
<p style="text-align: center;">
<p style="text-align: left;">In <a href="http://www.orbifold.net/default/?p=1055">Part II</a> we will discuss the MVC system.</p>
]]></content:encoded>
			<wfw:commentRss>http://visualizationtools.net/default/graphsquare-architecture-i/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WPF mindmapping in five minutes</title>
		<link>http://visualizationtools.net/default/wpf-mindmapping-in-five-minutes/</link>
		<comments>http://visualizationtools.net/default/wpf-mindmapping-in-five-minutes/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 20:34:18 +0000</pubDate>
		<dc:creator>Francois Vanderseypen</dc:creator>
				<category><![CDATA[Diagramming]]></category>
		<category><![CDATA[G2]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.orbifold.net/default/?p=1046</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>One of the things we had in mind while conceiving the diagramming library was to be able to do some mindmapping without much efforts. Well, the code below is the minimum for a mindmapping application on the basis of GraphSquare.</p>
<div class="wp_codebox">
<table>
<tr id="p104617">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
</pre>
</td>
<td class="code" id="p1046code17">
<pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//turn the diagramming surface into a mindmapping surface surface.CurrentPage.PageType = PageType.MindMap;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//You can add a child in one go.</span>
surface<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendChild</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ThoughtShape<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;A sub-node&quot;</span><span style="color: #008000;">&#41;</span>, surface<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentPage</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Root</span> <span style="color: #0600FF; font-weight: bold;">as</span> ThoughtShape<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//Or you can customize the node</span>
ThoughtShape t <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ThoughtShape<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Child of the root&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
t<span style="color: #008000;">.</span><span style="color: #0000FF;">Background</span> <span style="color: #008000;">=</span> Brushes<span style="color: #008000;">.</span><span style="color: #0000FF;">LightSlateGray</span><span style="color: #008000;">;</span>
surface<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendChild</span><span style="color: #008000;">&#40;</span>t, surface<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentPage</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Root</span> <span style="color: #0600FF; font-weight: bold;">as</span> ThoughtShape<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</td>
</tr>
</table>
</div>
<p>With the same ease one can turn the surface in a canvas with tree-layout. The resulting application (together with some info I added to highlight our API) looks like in the screenshot below.</p>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/simplemm.jpg"><img class="aligncenter size-medium wp-image-1047" title="Simple mind mapping" src="http://www.orbifold.net/default/wp-content/uploads/simplemm-300x178.jpg" alt="" width="300" height="178" /></a></p>
<p>Out of the box you get the gray/silver thought-shapes but one can turn on some themes and use the styling features of WPF. By simply adding a custom style in the Window resource or at the application level (the preferred way to save system resources) you get something like this:</p>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/mmstyling.jpg"><img class="aligncenter size-full wp-image-1048" title="Styled mindmapping nodes" src="http://www.orbifold.net/default/wp-content/uploads/mmstyling.jpg" alt="" width="427" height="51" /></a></p>
<p>The icons are easily added by means of code like</p>
<div class="wp_codebox">
<table>
<tr id="p104618">
<td class="line_numbers">
<pre>1
2
3
4
5
6
7
8
9
</pre>
</td>
<td class="code" id="p1046code18">
<pre class="csharp" style="font-family:monospace;">&nbsp;
ThoughtShape t<span style="color: #008000;">;</span>
t<span style="color: #008000;">.</span><span style="color: #0000FF;">Icon</span> <span style="color: #008000;">=</span> GetImage<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;category.gif&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">...</span>
<span style="color: #0600FF; font-weight: bold;">private</span> ImageSource GetImage<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> name<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  ImageSourceConverter imageSourceConverter <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ImageSourceConverter<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> imageSourceConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">ConvertFromString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;pack://application:,,/Resources/images/&quot;</span> <span style="color: #008000;">+</span> name<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> ImageSource<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre>
</td>
</tr>
</table>
</div>
<p>Of course, just with these feature you can go on and on, experiment and test various things. Obviously, sometimes you need to flip the diagram or rotate it, which can also be done with only one line of code</p>
<div class="wp_codebox">
<table>
<tr id="p104619">
<td class="line_numbers">
<pre>1
</pre>
</td>
<td class="code" id="p1046code19">
<pre class="csharp" style="font-family:monospace;">Surface<span style="color: #008000;">.</span><span style="color: #0000FF;">HandleCommand</span><span style="color: #008000;">&#40;</span>DiagramSurface<span style="color: #008000;">.</span><span style="color: #0000FF;">ChangeLayoutDirectionCommand</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre>
</td>
</tr>
</table>
</div>
<p><a href="http://www.orbifold.net/default/wp-content/uploads/morefunwithmm2.jpg"><img class="aligncenter size-full wp-image-1049" title="More fun" src="http://www.orbifold.net/default/wp-content/uploads/morefunwithmm2.jpg" alt="" width="500" height="188" /></a></p>
<p>To complete this little intro to GraphSquare&#8217;s I should mention the following features:</p>
<ul>
<li>full undo-redo</li>
<li>totally, completely fully MVC (or <a title="The WPF MVC confusion" href="http://www.orbifold.net/default/?p=550" target="_blank">MVP or MVCP or MMVC</a>)</li>
<li>multi-page and multi-layer support built into the control</li>
<li>styling, themes, templates and the whole WPF customization</li>
<li>extensibility through our own plugable system and <a title="Unity injection" onclick="urchinTracker('/outgoing/www.codeplex.com/unity?referer=');" href="http://www.codeplex.com/unity" target="_blank">Unity</a></li>
<li>data abstraction and adapters for XML, binary and relational data</li>
<li>runtime scripting</li>
</ul>
<p>In addition, you can expect more from <a title="Denis Vuyka's blog" onclick="urchinTracker('/outgoing/dvuyka.spaces.live.com/default.aspx?referer=');" href="http://dvuyka.spaces.live.com/default.aspx" target="_blank">Denis </a>on our <strong>server-side diagramming solution (baptized G2 Server) </strong>and many more high-end features.</p>
<div><img src="http://www.orbifold.net/default/wp-content/uploads/snag-program-0000.png" alt="" /></div>
]]></content:encoded>
			<wfw:commentRss>http://visualizationtools.net/default/wpf-mindmapping-in-five-minutes/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  www.visualizationtools.net/default/category/orbifold/products-orbifold/g2/feed/ ) in 1.59326 seconds, on Feb 4th, 2012 at 11:40 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 4th, 2012 at 12:40 pm UTC -->
