Пример #1
0
      reset: function() {
        dispatch.willReset();
        propertySupport.invalidatingChangePreHook();

        model.stop();
        coreModel.reset();

        var parts;
        // Validate parts before passing options to coreModel.
        if (initialProperties.structure && initialProperties.structure.part) {
          parts = validateParts(initialProperties.structure.part);
        }
        coreModel = coremodel.makeCoreModel(model.properties, parts);
        setWebGLEnabled(model.properties.use_WebGL);
        if (initialProperties.sensors) {
          createSensors(initialProperties.sensors);
        }
        updatePartsViewModel();
        updateSensorViewModel();

        propertySupport.invalidatingChangePostHook();
        model.resetAllOutputProperties();
        dispatch.reset();
        dispatch.invalidation();
      },
Пример #2
0
    (function () {
      var parts;

      labModelerMixin.mixInto(model);
      dispatch.addEventTypes("tick", "partsChanged", "sensorsChanged");

      // Validate parts before passing options to coreModel.
      if (initialProperties.structure && initialProperties.structure.part) {
        parts = validateParts(initialProperties.structure.part);
      }

      coreModel = coremodel.makeCoreModel(model.properties, parts);
      setWebGLEnabled(model.properties.use_WebGL);

      if (initialProperties.sensors) {
        createSensors(initialProperties.sensors);
      }

      updatePartsViewModel();
      updateSensorViewModel();

      // FIXME. More yuck: We still need a pattern for recompute model properties which don't depend
      // on physics (and which therefore can be recomputed without invalidating and recomputing all
      // the physics based properties) while still making them (1) observable and (2) read-only.

      // used to triggers recomputation of isPlayable property based on isStopped and isReady:
      model.on('play.model', recomputeProperties);
      model.on('stop.model', recomputeProperties);

      function recomputeProperties() {
        propertySupport.invalidatingChangePreHook();
        propertySupport.invalidatingChangePostHook();
      }

      // Temporal workaround. In fact width and height should
      // be outputs based on min / max.
      model.defineOutput('minX', {}, function() {
        return 0;
      });
      model.defineOutput('minY', {}, function() {
        return 0;
      });
      model.defineOutput('maxX', {}, function() {
        return model.properties.model_width;
      });
      model.defineOutput('maxY', {}, function() {
        return model.properties.model_height;
      });

      model.defineOutput('time', {
        label: "Time",
        unitType: 'time',
        format: '.2f'
      }, function() {
        return model.getTime();
      });

      model.defineOutput('displayTime', {
        label: "Time"
      }, (function() {
        var f = d3.format("02d");
        return function() {
          var time = model.getTime(),
              seconds, minutes, hours, days;
          time = Math.floor(time);
          seconds = time % 60;
          time = Math.floor(time / 60);
          minutes = time % 60;
          time = Math.floor(time / 60);
          hours = time % 24;
          time = Math.floor(time / 24);
          days = time;
          return days + ':' + f(hours) + ':' + f(minutes)  + ':' + f(seconds);
        };
      }()));

      (function() {
        var hasPlayed = false;
        model.on('play.has-played-support', function () {
          hasPlayed = true;
        });
        model.on('reset.has-played-support', function () {
          hasPlayed = false;
        });
        model.defineOutput('hasPlayed', {
          label: "has Played"
        }, function() {
          return hasPlayed;
        });
      }());
    }());