Skip to content

Adapt the world's representation

Matthieu NICOLAS edited this page Jan 4, 2016 · 1 revision

The world's representation

The first step to adapt an existing PLM's universe to webPLM is to implement the new world's representation. In order to represent a world, we implemented the following workflow:

  • The server convert and send the world's data to the client
  • The client initializes its local model according to the received data
  • The client draws the world representation from its local model

Convert the world's model into a unified format

The first step is to add conversion methods to transmit the world's data to the client. The unified format we have chosen is JSON. Remember that the client only need to draw the world, so don't put everything into the JSON result but only what is needed

Implement the simplified model

We now need to implement the simplified client's model of the world:

Implement the drawing method

  • In the universe's directory, add <universe>worldview.factory.js
    • This service has to provide the method draw()
    • To implement draw(), you can use:

Add the new universe to supported universes

Regenerate the PLM's jar file

We may need to add the lesson which use this new universe. In this case, we need to:

Add new script files to the HTML

We need to reference in the HTML to make the new data models available. Just add the scripts to index.scala.html.

Handle the new type of world in ExerciseController

First, inject the new models in the controller by adding them to the directive $inject (exercise.controller.js#L8-L24) and to the constructor (exercise.controller.js#L26-L39). Be sure to respect the same order in both otherwise some nasty bugs are bound to appear!

All we need to do now is to edit https://github.com/BuggleInc/webPLM/blob/master/public/app/exercise/exercise.controller.js#L239-L259 to add the new universe's case. You need to set:

  • exercise.tabs, the tabs which will allow the user to switch from the working world to the objective one
    • name is the label of the tab
    • worldKind is the kind of world which will be displayed. Two values are available:
      • current, the user's working copy
      • answer, the objective world
    • tabNumber, the tab's index
    • __, the function draw() used to represent this world
  • exercise.drawFnct, the initial function draw() to use
  • exercise.animationPlayerNeeded, if the component allowing to switch between state should be shown or not
  • world, thedrawFnct world's model

And finally we need to initialize the drawing service used with draw():

  • initCanvas(drawFnct);
  • initDrawWithDOM(drawFnct);

Congratulations, the world will (or at least should) now be correctly displayed! To continue to adapt the universe to webPLM, you may want to take a look at Adapt the world's evolution.