I was recently asked how I would approach improving the Logic Gate 2 in the Circuits and Logic template, on the Analog and Digital Logic stencil. Well, this had resonance with me because I had often wondered why these shapes were not smarter than they are, so I looked more deeply into the shape construction to see how the Logic Gate 2 shape works, and how it could be improved so that the values of the inputs could be set and the logic applied to provide the correct output value. Eventually, similar improvements can be applied to all of the master shapes so that the connected logic diagram responds to input value changes.
The Existing Shape
The Logic Gate 2 shape has Shape Data rows to provide some configuration. Firstly, you can change the number of inputs from 2 to 5, and the number of outputs from 1 to 3:
Secondly, you can change the gate type between OR; AND; NOR; NAND; XOR and XNOR:
The Logic Gate 2 shape is basically the same in Visio 2013, but I thought it worthwhile checking how the new themes renders the shape:
The first decision that I made was to provide Shape Data rows for each of the inputs, numbered from 1 to 5, and it seemed logical that they should be read from top to bottom on the left side of the shape.
However, an exploration of the master shape reveals that the inputs are actually geometry sections of two sub shapes, Sheet.13, which contains the middle 3 inputs and the 3 outputs, and Sheet.15, which contains the upper and lower inputs when there are 4 or 5 inputs.
So, the input lines do not correspond to the same input number if the number of inputs is varied from 2 to 5, however I first needed to add the input Shape Data rows as True/False (boolean) data type, and the display of the output value. I also decided that it would be useful to have the ability to select the value of inputs from the right-mouse menu:
I added Prop.Input_01 through to Prop.Input_05 as Shape Data rows, and controlled their visibility according to the number of inputs selected.
The formula in the Prop.Output row is guarded because its value is derived from the result of formulas in the User-defined Cells section:
Each of the input Actions rows need to toggle the value of the corresponding Shape Data row, and to display the current value as checked or not (TRUE or FALSE). Also, their visibility needs to be set by the number of inputs selected.
I decided that it would be nice to have the “Inputs” header row on the right-mouse menu, and so this is achieved i Action.Row_2 by having it as ReadOnly = TRUE
I have already mentioned that the output value is calculated by formulas in the User-defined Cells section, and I decided that it was clearer to and result rows for each of the different gate types.
As these formulas are central to the validity of this shape, I have listed the formulas for each one below (remember that each one is on a single line in the cell):
This cell just selects the relevant value for the selected gate type.
The existing Connection Points have their position controlled by suitable formulas in the X and Y cells.
However, the Type of rows 3,4 and 5 can be changed automatically to 1 according to the number of inputs selected, so they are not available for connecting to when they are not visible.
Visual Representation of True or False
My original inquirer suggested that True or False could be represented by changing the line colour to red if the value is positive. I have two problems with this approach: Firstly, any print out could be in black and white; and secondly, users might want to apply a theme to the diagram, which would probably be at odds with the red line.
In the following example, I have applied one of the built-in themes, and then changed one of the sub-shapes to a red line.
Here, I have done similar in Visio 2013.
Perhaps, the red line is obvious enough, but it does emphasize that I would need to have a different sub-shape for each input, so that they can be coloured separately.
The line pattern could be changed to represent True or False, but increasing the Line Weight will increase the space between any elements in the line, as can be seen by the following example from Visio 2010:
There is similar behaviour in Visio 2013
Line Ends (Arrows)
Visio has a number of Line Ends (Arrows) built in, and you can create custom ones too. A quick application of different Begin and End Arrow shows that the existing shape is not well made, because it does not inhibit inappropriately assigned arrows, and it does not have an input (Begin) and output (End) flow.
You can create a custom Line End too, as in the following example where I created a Line End master called True, which consists of a vertical dashed line.
The logical textual display for True and False is + and –, as in the following example for the first input:
The problem with this is that the extra text could make the diagram too busy, and could get obscured by heavier lines easily.
My conclusion is that the existing shape needs to be enhanced anyway, and that it needs to have a separate shape for each input line if the line pattern, color, arrow or text is going to change according a Shape Data row value.
If a connector line is going to be enhanced in the future to visualise True or False, then either the line pattern or color could be used, but line arrows and text could become too busy, and detract from the simplicity.
So, I concluded that either or both the line pattern and color could be used to represent True or False, but that it would be useful to provide the user with the choice.
Updating the Master
I named all of the sub-shapes inside the group, and added separate shapes for each of the inputs, named InputA to InputE from top to bottom on the left.
I have outlined some of the main changes below….
The Master Page
I added the options for the display of True / False values to the page of the master, so that all shapes will have access to the values.
I also added a User-defined cell, User.TrueColor, to store the value for lines that represent True values, and another cell, User.FalsePattern, to store the line pattern to represent False values.
I decided that RGB(255,0,0), red, should indeed represent True, as suggested by my original requestor (because it is like the positive jump lead for my car battery!), and that False lines should be a tight dotted line (23).
The Outputs sub-shape contains all of the possible lines at the right of the shape. They are just separate geometry sections, and thus share the same LinePattern and LineColor values.
The input sub-shapes
I noticed that the original master shape was protected from theme effects, but this causes an unfortunate mis-match of line weights with some of the standard themes:
So, I removed the protection from theme effects on the group shape, but applied it to all the sub-shapes. Then I added the formula =GUARD(Sheet.5!LineWeight) to the LineWeight cell of all of the sub-shapes. This ensures that the line weight of any applied theme is respected in the sub-shapes:
The example above reveals how the solution seems incomplete with adding a little smartness to the Dynamic connector master. So, I added the same master page cells that I did for the Logic Gate 2 master above, added a Prop.Value Shape Data row, and then updated the formulas for the LinePattern and LineWeight.
In the future, I may add code to update the Prop.Value from the True/False value of the Output at the start of the connector, but, for now, I can just edit the value manually.
So, my revised document now contains two masters, and I ensured that their Match master by name on drop property is ticked, so that you can drag and drop from the built-in stencil, just like normal, but my revised Logic Gate 2 master shape will be used.
You can download the template from the links below (note that you should have a licence for Visio Professional or higher) :
Visio 2003 – 2010 format
Visio 2013+ Format
You can read more about logic gates at http://en.wikipedia.org/wiki/Logic_gate.
There are only 26 masters on the Analogue and Digital Logic stencil, and I haven’t counted how many there are on the three stencils docked in this template…. but if Microsoft want to employ someone to update the Visio 2013 masters ….
My friend, John Marshall, pointed out that the original Visio shape did not have the outer negation circles centred, so I have updated the master shape in the download, and created Metric and US Unit versions.