CmdSetGeometryValue.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.name = 'Set Geometry.' + attributeName;
  8. this.object = object;
  9. this.attributeName = attributeName;
  10. this.oldValue = ( object !== undefined ) ? object.geometry[ attributeName ] : undefined;
  11. this.newValue = newValue;
  12. this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
  13. };
  14. CmdSetGeometryValue.prototype = {
  15. execute: function () {
  16. this.object.geometry[ this.attributeName ] = this.newValue;
  17. this.editor.signals.objectChanged.dispatch( this.object );
  18. this.editor.signals.sceneGraphChanged.dispatch();
  19. this.editor.signals.updateSidebar.dispatch();
  20. },
  21. undo: function () {
  22. this.object.geometry[ this.attributeName ] = this.oldValue;
  23. this.editor.signals.objectChanged.dispatch( this.object );
  24. this.editor.signals.sceneGraphChanged.dispatch();
  25. this.editor.signals.updateSidebar.dispatch();
  26. },
  27. toJSON: function () {
  28. var output = Cmd.prototype.toJSON.call( this );
  29. output.objectUuid = this.objectUuid;
  30. output.attributeName = this.attributeName;
  31. output.oldValue = this.oldValue;
  32. output.newValue = this.newValue;
  33. return output;
  34. },
  35. fromJSON: function ( json ) {
  36. Cmd.prototype.fromJSON.call( this, json );
  37. this.objectUuid = json.objectUuid;
  38. this.attributeName = json.attributeName;
  39. this.oldValue = json.oldValue;
  40. this.newValue = json.newValue;
  41. this.object = this.editor.objectByUuid( json.objectUuid );
  42. }
  43. };