Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note that this is not Java, but Xtend code. Xtend is a language that compiles to Java and has a bunch of nifty little features that make writing a synthesis easier. The main entry point of our synthesis is the transform method. As you can see, the method gets a TuringMachine instance and returns a KNode. That KNode will contain our actual diagram.

Visualizing States

Let's start by adding nodes for all states in the Turing machine.

  1. Add a new method to your synthesis that transforms a State into a corresponding KNode:

    Code Block
    languagejava
    linenumberstrue
    private def KNode transform(State state) {
        val stateNode = state.createNode().associateWith(state);
    
        return stateNode;
    } 
  2. While this method does indeed create a node for the state passed to it, KLighD wouldn't know how to render it yet. Let's draw the node as a rounded rectangle by adding the following line before the return statement:

    Code Block
    languagejava
    linenumberstrue
    stateNode.addRoundedRectangle(4, 4, 2);
  3. The only thing missing now is a label with the state's name:

    Code Block
    languagejava
    linenumberstrue
    stateNode.addInsideCenteredNodeLabel(state.name,
        KlighdConstants.DEFAULT_FONT_SIZE,
        KlighdConstants.DEFAULT_FONT_NAME);
    stateNode.addLayoutParam(
        LayoutOptions.SIZE_CONSTRAINT,
        EnumSet.of(SizeConstraint.MINIMUM_SIZE, SizeConstraint.NODE_LABELS));

Let's see if our visualization works. Start your program (if you don't know how to do that, check out our Eclipse Plug-ins and Extension Points tutorial) and follow these steps:

  1. Right-click the Package Explorer and select New -> Project.
  2. In the dialog, select General -> Project and click Next.
  3. Give the project a meaningful name (Foo is a classic) and click Finish.
  4. Right-click your new project in the Package Explorer and select New -> Other.
  5. In the dialog, select Example EMF Model Creation Wizards -> Turingmachine Model and click Next.
  6. Give your Turing machine file a meaning