CmdSetGeometryValue.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Created by Daniel on 21.07.15.
  3. */
  4. CmdSetGeometryValue = function ( object, attributeName, newValue ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetGeometryValue';
  7. this.object = object;
  8. this.attributeName = attributeName;
  9. this.oldValue = object !== undefined ? object.geometry[ attributeName ] : undefined;
  10. this.newValue = newValue;
  11. this.objectUuid = object !== undefined ? object.uuid : undefined;
  12. };
  13. CmdSetGeometryValue.prototype = {
  14. execute: function () {
  15. this.object.geometry[ this.attributeName ] = this.newValue;
  16. this.editor.signals.objectChanged.dispatch( this.object );
  17. this.editor.signals.sceneGraphChanged.dispatch();
  18. this.editor.signals.updateSidebar.dispatch();
  19. },
  20. undo: function () {
  21. this.object.geometry[ this.attributeName ] = this.oldValue;
  22. this.editor.signals.objectChanged.dispatch( this.object );
  23. this.editor.signals.sceneGraphChanged.dispatch();
  24. this.editor.signals.updateSidebar.dispatch();
  25. },
  26. toJSON: function () {
  27. var output = Cmd.prototype.toJSON.call( this );
  28. output.objectUuid = this.objectUuid;
  29. output.attributeName = this.attributeName;
  30. output.oldValue = this.oldValue;
  31. output.newValue = this.newValue;
  32. return output;
  33. },
  34. fromJSON: function ( json ) {
  35. Cmd.prototype.fromJSON.call( this, json );
  36. this.objectUuid = json.objectUuid;
  37. this.attributeName = json.attributeName;
  38. this.oldValue = json.oldValue;
  39. this.newValue = json.newValue;
  40. this.object = this.editor.objectByUuid( json.objectUuid );
  41. }
  42. };