Flow Charts

The Flow Charts provide visualization of the control flow, or program logic, occurring inside the functions in your software. For complex functions that may consist of hundreds of lines of source code, these diagrams can help you more quickly grasp the internal logic of the routine.

A Flow Chart diagram presents the complete internal logic, of a single function at a time. For the next level higher level of abstraction - multiple functions but with reduced internal logic - use the Sequence Diagrams.

Display / Layout

void WhileControl() {
    int pos = do_init();
    int ext = 1;
    while (pos != 1) {
        if (!pos) {
            if (ext != get_meter()) {
                ext = reset_valve(ext);
	    }
	}
	else if (check_pos(pos)) {
	    raise_valve(ext);
	}
	else {
	    lower_valve(ext);
	}
	pos = read_pos();
    }
    signal_done(pos);
}
Generally, all decision points (such as if statements or switch statements) within a function are represented by symbols in the diagram. Other symbols are used to indicate in-line blocks of code. The actual flow of control is indicated by the lines connecting these symbols. The specific symbols used and the placement of the symbols in the diagram are controlled by selecting a layout (Display > Layout).

There are four layout alternatives to choose from. Each is optimized to show a different aspect of the program logic and control structure of a function. Further options under the Display menu control additional aspects of the detail presented in the diagrams.

For illustration, consider this source code (right):

The default layout is Logic. The control flow is from top to bottom. Beyond that, the layout is optimized for understanding and tracing the program logic, rather than emphasizing the details of the control statements making up the decision structure.

Within a given layout, you control how much detail is displayed. In the diagram shown, the generally diamond-shaped decision symbols contain the source code for the decision. An alternative setting reduces the contents to just the name of decision type (such as if/else). For blocks of in-line code, the rectangles can contain function calls (as shown), the entire body of in-line source code, or remain empty.

In contrast, control structure is explicitly represented in the Structure layout. The logic flow is once again top to bottom. However, decision branches are explicitly laid out in parallel, and the opening of each control statement has a corresponding closing point.

Reviewing a Structure layout results in an understanding of not only the logic, but also of the if / for / while / switch control structure that underpins that logic.

The final two layouts use smaller, less descriptive symbols to represent the decision points and in-line code. The Compact layout (right) mirrors that of the Structure layout, with opening and closing points for decision paths, etc. However, all information about the actual source code is omitted, so the entire focus is on reviewing just the structure itself.

In the Sequence layout (far right), no decisions or blocks of code are drawn in parallel. The top to bottom drawing of the flow chart mirrors the sequence of lines of code in the source file. This alternative provides a useful map for understanding where specific lines of code lie within the control logic.

Diagram Reduction

For large, complex functions, the program logic represented in the diagram may have such complexity that it impedes initial understanding. In such cases, you might want to start by examining the higher level control loops, before diving down into particular parts of the control flow.

The Flow Charts include a collapse action to enable this. Through the right-click menu, you can choose to collapse the internal program logic for any given decision points. All interior decisions up to the matching closing brace are hidden, and you're left with a diagram showing the control flow down to the level that you choose.

Tool Integration

Part of the value in understanding your code using the Flow Charts derives from their integration with the rest of Imagix 4D.

Through the Highlight menu, you can identify where specific items exist within the control flow. Typically, these items are symbols. A number of highlight alternatives exist. You can find everywhere that functions are called, variables are set, or variables are used. You can identify everywhere that specific functions and/or variables are used by selecting them in the Graph window. This diagram (right) was created by selecting the variable "ext" in the Graph window, which resulted in yellow highlighting you see.

The Flow Charts are tied particularly closely to Imagix 4D's File Editors. Highlight selections include Editor Selection and Editor Search. So for example, you can search for strings in your file editor, and see where those strings occur within the control flow of the function.

The Flow Charts and File Editors are also tied together for browsing through your code. You might display the program logic and source code side-by-side, scroll to a certain point in one, and immediately see where the corresponding point exists in the other. In this way, you can speed you understanding and review of complex functions.

Shortcut: The File Editor can be opened and scrolled to a point in the Flow Chart by double-clicking or Shift-left clicking on a point in the Flow Chart. The exception occurs when clicking on a function listed inside an in-line rectangle, in which case Imagix 4D behaves the same as anywhere else when you click on a function name / symbol.

Shortcut: The Flow Chart can be opened and scrolled to a point in the File Editor by Control-left clicking on any point inside a function definition in the File Editor.